1
00:00:02,540 --> 00:00:03,800
Hey What's up everybody.

2
00:00:03,830 --> 00:00:10,750
Mark Price here at the slopes a dot com and today we're going to talk about numbers and you're like

3
00:00:11,320 --> 00:00:14,680
wait a minute I thought we were doing programming what the heck are we doing.

4
00:00:14,680 --> 00:00:20,650
Going back to like fifth grade math first grade whenever you can but numbers probably in kindergarten.

5
00:00:21,220 --> 00:00:21,790
Yeah that's right.

6
00:00:21,790 --> 00:00:25,450
Today's episode is brought to you by the number three.

7
00:00:26,110 --> 00:00:26,560
OK.

8
00:00:26,710 --> 00:00:33,310
So really though open up your excavator and create a new playground if you're following along.

9
00:00:33,310 --> 00:00:35,050
Otherwise you can just watch.

10
00:00:35,140 --> 00:00:41,460
And we're going to call this one numbers and I'm going to create a new folder for a year.

11
00:00:41,530 --> 00:00:44,690
It's always nice to organize your code and projects in the folders.

12
00:00:44,770 --> 00:00:50,710
Swift and this one is going to be called numbers or to save it here.

13
00:00:50,770 --> 00:00:57,970
So numbers are a core foundational building block to any programming language.

14
00:00:58,030 --> 00:01:03,180
And when you think about it you interact with numbers all the time in any application that you're using.

15
00:01:03,250 --> 00:01:07,660
For instance if you go to Wells-Fargo dot com to log into your bank account you're going to see your

16
00:01:07,660 --> 00:01:09,670
bank account balance and has numbers in it.

17
00:01:09,790 --> 00:01:10,340
OK.

18
00:01:10,420 --> 00:01:17,390
If you are using a workout app and one week you weighed like 150 pounds in the next week you weight

19
00:01:17,410 --> 00:01:22,190
170 pounds because who knows what you're doing with yourself.

20
00:01:22,810 --> 00:01:24,490
You have to use numbers to show that to the user.

21
00:01:24,490 --> 00:01:25,380
Numbers are everywhere.

22
00:01:25,390 --> 00:01:30,610
And it had to do math in order to calculate how many calories you consume in all those different things.

23
00:01:30,610 --> 00:01:36,690
So numbers are everywhere and every application just like this is a string and there's words and applications

24
00:01:36,710 --> 00:01:39,390
OK use numbers and use words.

25
00:01:39,400 --> 00:01:44,280
I know it sounds basic but those are foundational variable types in any language.

26
00:01:44,290 --> 00:01:49,810
But there's different types of numbers so let's get rid of this string variable here and let's create

27
00:01:49,810 --> 00:01:51,910
a new variable.

28
00:01:52,060 --> 00:01:52,810
Some numbers.

29
00:01:52,810 --> 00:01:59,210
Right now we don't just say bar some number you know equals number.

30
00:01:59,230 --> 00:02:02,860
You know there's no what is the number you know there's no real number.

31
00:02:02,860 --> 00:02:03,460
OK.

32
00:02:03,640 --> 00:02:10,690
Well you have to do is actually create different types of numbers such as integers floats and doubles

33
00:02:11,270 --> 00:02:12,050
and is more.

34
00:02:12,310 --> 00:02:20,170
So for instance if it were a person write a program for a person maybe this is one of those apps that

35
00:02:20,760 --> 00:02:25,870
cak calculates and tracks calorie burning and things like that shows you how much junk food you're eating

36
00:02:26,050 --> 00:02:26,390
you know.

37
00:02:26,390 --> 00:02:30,100
So let's go ahead and say well we have to have a profile.

38
00:02:30,100 --> 00:02:42,540
So we have an age right or not origo a person has an age to say age 30 and let's say var weight.

39
00:02:42,840 --> 00:02:44,070
Well that's two pounds.

40
00:02:44,200 --> 00:02:49,390
That's how we roll in the US of A weight equals we're going to say 200.

41
00:02:49,390 --> 00:02:51,180
So this person weighs 200 pounds.

42
00:02:51,190 --> 00:02:51,990
OK.

43
00:02:52,420 --> 00:02:56,410
Does anyone know what variable type this is.

44
00:02:56,470 --> 00:02:56,960
OK.

45
00:02:57,160 --> 00:03:04,320
Well these are actually called int or integers but in swift The key word is actually into like so.

46
00:03:04,340 --> 00:03:11,200
So what we can do here is I can put a colon here and then I can put in the keyword and the variable

47
00:03:11,200 --> 00:03:11,530
name.

48
00:03:11,530 --> 00:03:19,210
And what we're doing right here is creating an explicitly declared type before we were creating a variable

49
00:03:19,210 --> 00:03:23,370
with an inferred type meaning the variable is smart enough to know what you're putting in it.

50
00:03:23,380 --> 00:03:26,630
And so it knows that it's and knows that it's an event.

51
00:03:26,650 --> 00:03:31,130
For instance I can't say age equals peanuts.

52
00:03:31,180 --> 00:03:39,130
I have to try and break the program that cannot assign value of type string to type int.

53
00:03:39,130 --> 00:03:44,230
OK so you cannot put different data types inside of a variable and it was smart enough to know that

54
00:03:44,230 --> 00:03:45,240
this was an int.

55
00:03:45,250 --> 00:03:46,860
So this is the key word here.

56
00:03:47,140 --> 00:03:52,320
This is an inferred or let's just call this type inference.

57
00:03:52,390 --> 00:03:55,100
That's the proper term type inference.

58
00:03:55,120 --> 00:03:56,530
It inferred what type it was.

59
00:03:56,540 --> 00:04:01,450
It's no different than this except it did automatically and by the way this is the recommended way in

60
00:04:01,450 --> 00:04:06,640
swift if at all possible use type inference and if you have to use an explicit declaration do it don't

61
00:04:06,640 --> 00:04:09,500
just do this because you think it looks nicer.

62
00:04:09,500 --> 00:04:14,150
That's not the swift way with boys like this but this is an explicitly declared type.

63
00:04:14,170 --> 00:04:14,910
OK.

64
00:04:15,520 --> 00:04:20,370
So this isn't explicitly declared type.

65
00:04:20,370 --> 00:04:24,100
Those are the key words and phrases right there explicitly declared because we actually wrote what type

66
00:04:24,100 --> 00:04:25,090
it was.

67
00:04:25,150 --> 00:04:30,820
And again the same thing here we can't say Wait equals no way.

68
00:04:31,090 --> 00:04:33,710
All right we can't can't spell either.

69
00:04:34,090 --> 00:04:35,520
That's why we need to work with numbers.

70
00:04:35,640 --> 00:04:35,990
OK.

71
00:04:36,220 --> 00:04:37,120
So can't do it right.

72
00:04:37,140 --> 00:04:39,230
It's the same exact thing no difference.

73
00:04:39,400 --> 00:04:41,110
So pretty cool.

74
00:04:41,110 --> 00:04:43,250
So we've got we've got some int here.

75
00:04:43,480 --> 00:04:44,690
And what is an integer.

76
00:04:44,950 --> 00:04:45,790
OK what is an integer.

77
00:04:45,800 --> 00:04:48,700
Well let's go pull open the Swift book.

78
00:04:48,700 --> 00:04:53,860
If you don't have it already and if you don't have it please get it.

79
00:04:53,860 --> 00:04:55,920
Go to books.

80
00:04:56,020 --> 00:04:57,640
This is super important.

81
00:04:57,640 --> 00:04:59,450
Get this book if you don't have it.

82
00:04:59,620 --> 00:05:06,510
I said go to books were already in books and then do a search for swift not Dora the Explorer.

83
00:05:06,520 --> 00:05:10,330
Dora meets Pablo That's my personal reading just forget that you saw that.

84
00:05:10,480 --> 00:05:12,690
And the swift program mealing.

85
00:05:12,700 --> 00:05:15,700
How did that get on here anyway.

86
00:05:15,820 --> 00:05:18,030
Swift three editions the one that you want.

87
00:05:18,610 --> 00:05:19,890
That's right.

88
00:05:20,170 --> 00:05:22,730
Right here don't do the one with Coco an object.

89
00:05:22,750 --> 00:05:26,820
You do this right here and get that book and read through the entire thing.

90
00:05:26,890 --> 00:05:32,950
I promise you won't you won't regret it and I'll make you a much better programmer so integers are whole

91
00:05:32,950 --> 00:05:39,820
numbers with no fractional component such as 42 and negative 23 integers are either signed positive

92
00:05:39,820 --> 00:05:43,530
zero or negative or unsigned positive or zero.

93
00:05:43,710 --> 00:05:48,990
So if preside signed an unsigned integers and 8 16 32 and 64 bit forums.

94
00:05:49,210 --> 00:05:55,120
And what that means is 64 bit 32 bit it's how many characters how many digits it can hold the actual

95
00:05:55,120 --> 00:05:55,900
value.

96
00:05:56,030 --> 00:06:01,570
You know if someone had a trillion dollar bank account you know you're probably not going to use this

97
00:06:02,050 --> 00:06:06,310
energy and use something larger but Swift is smart enough to do all that for you automatically just

98
00:06:06,310 --> 00:06:08,990
know that there are some different things going on under the hood.

99
00:06:09,340 --> 00:06:12,350
And so you can see some of the types here like you and Kate.

100
00:06:12,520 --> 00:06:12,990
OK.

101
00:06:13,000 --> 00:06:16,200
And a 32 bit sign in terms of type in 2:32.

102
00:06:16,270 --> 00:06:18,450
So it just depends.

103
00:06:18,460 --> 00:06:19,780
It shows how much it holds.

104
00:06:19,790 --> 00:06:25,840
Again you don't ever need to worry about this pretty much in swift for the most part you're never ever

105
00:06:25,840 --> 00:06:29,720
going to have to do anything else except this standard.

106
00:06:29,890 --> 00:06:32,730
Ok but again you can you can do different things.

107
00:06:32,740 --> 00:06:38,720
You know some them you know and you could say you can't or is it you.

108
00:06:39,250 --> 00:06:41,590
Eight 16 32 64.

109
00:06:41,740 --> 00:06:43,330
Now you can do different things like that.

110
00:06:43,450 --> 00:06:44,660
OK.

111
00:06:45,280 --> 00:06:47,210
But you don't want to be careful.

112
00:06:47,320 --> 00:06:48,190
You know you don't want to.

113
00:06:48,330 --> 00:06:50,340
You don't want to do something that you can't.

114
00:06:50,350 --> 00:06:56,190
You can't do it because it will overflow the variable into your literal overflows when stored in you

115
00:06:56,240 --> 00:06:58,740
it's too big too big of a number.

116
00:06:58,810 --> 00:07:03,460
And so again don't play around with the zombie like oh I want to be more memory efficient and use smaller

117
00:07:03,520 --> 00:07:04,320
integers.

118
00:07:04,340 --> 00:07:05,200
Now don't do that.

119
00:07:05,200 --> 00:07:07,810
Always always always use it.

120
00:07:07,930 --> 00:07:08,410
OK.

121
00:07:08,530 --> 00:07:11,150
Always always always use an integer.

122
00:07:11,320 --> 00:07:13,730
I think actually this one is too big even for integer.

123
00:07:13,870 --> 00:07:23,290
So in this case you probably have to use a data type that even longer like a long or something Swift

124
00:07:23,350 --> 00:07:27,560
I think it's a double that did the trick.

125
00:07:27,560 --> 00:07:32,650
There you go doubles double precision double to twice as long.

126
00:07:32,690 --> 00:07:33,580
More or less.

127
00:07:33,810 --> 00:07:38,970
Anyway there is another data type which allows you to have incredibly long values here.

128
00:07:39,050 --> 00:07:39,410
OK.

129
00:07:39,450 --> 00:07:40,640
Look this is just huge.

130
00:07:40,640 --> 00:07:42,110
I don't even know what number that is.

131
00:07:42,110 --> 00:07:45,440
OK so we have integer which you want to use at any given time.

132
00:07:45,470 --> 00:07:49,260
If a number does not have decimal points a note nothing.

133
00:07:49,310 --> 00:07:50,740
No dot.

134
00:07:50,820 --> 00:07:53,490
You know whatever you want to use it.

135
00:07:53,510 --> 00:07:53,930
OK.

136
00:07:53,930 --> 00:07:57,260
Always always always use it if you need a long number.

137
00:07:57,260 --> 00:08:00,030
Double is the favorite choice here.

138
00:08:00,170 --> 00:08:00,840
OK.

139
00:08:01,190 --> 00:08:04,790
So you can also on double.

140
00:08:04,790 --> 00:08:05,750
This is cool.

141
00:08:06,200 --> 00:08:08,090
If you had something like let's say a bank account right.

142
00:08:08,090 --> 00:08:11,370
So actually no we're doing what are we doing here.

143
00:08:11,420 --> 00:08:13,260
We're doing an exercise.

144
00:08:13,270 --> 00:08:18,940
So let's say Miles ran our miles ran and we ran.

145
00:08:19,220 --> 00:08:20,100
Equals.

146
00:08:20,420 --> 00:08:21,340
We've run in the whole week.

147
00:08:21,350 --> 00:08:24,550
Fifty six point four five miles.

148
00:08:24,560 --> 00:08:27,550
So what type is this.

149
00:08:27,570 --> 00:08:31,670
This is actually a double.

150
00:08:31,670 --> 00:08:32,180
That's pretty cool.

151
00:08:32,180 --> 00:08:36,470
So by default swift uses doubles which has double the precision.

152
00:08:36,470 --> 00:08:41,690
In fact let's pull our handy dandy book here like I didn't pay X amount of dollars for this course or

153
00:08:41,690 --> 00:08:42,920
you can read a book to me.

154
00:08:42,980 --> 00:08:45,730
I wanted you to say those words without looking at a book.

155
00:08:46,000 --> 00:08:47,420
Does that make any sense.

156
00:08:47,420 --> 00:08:50,040
No it's better to have it straight from the horse's mouth.

157
00:08:50,060 --> 00:08:51,230
And I do this a lot.

158
00:08:51,250 --> 00:08:52,550
Get used to it.

159
00:08:52,550 --> 00:08:54,560
It is so important to read the documentation.

160
00:08:54,620 --> 00:08:58,650
Like seriously if you go to your boss every single day like how do you do this how do you do this you're

161
00:08:58,670 --> 00:08:59,570
going to fire you.

162
00:08:59,720 --> 00:09:02,800
I wouldn't have an employee like that you've got to learn how to learn.

163
00:09:02,810 --> 00:09:04,280
So always go back to the documentation.

164
00:09:04,280 --> 00:09:08,260
I'm trying to train you here how to be a lifelong learner and programmer.

165
00:09:08,270 --> 00:09:13,670
So where was I before I started lecturing you on things you really didn't care about.

166
00:09:14,130 --> 00:09:14,330
OK.

167
00:09:14,340 --> 00:09:15,860
So we talked about integers.

168
00:09:16,070 --> 00:09:16,630
OK.

169
00:09:17,030 --> 00:09:21,690
Floating point numbers floating point numbers or numbers with a fractional component such as 3.1 for

170
00:09:22,190 --> 00:09:24,580
maybe you're thinking wait you just did double wide.

171
00:09:24,640 --> 00:09:25,880
Why.

172
00:09:26,120 --> 00:09:28,000
Why didn't we do a float with the decimals.

173
00:09:28,010 --> 00:09:32,540
Well read this double as a precision of at least 15 decimal digits.

174
00:09:32,540 --> 00:09:34,430
OK so 15 decimal digits.

175
00:09:34,490 --> 00:09:37,780
Where is the precision of a flow can be as little as six decimal digits.

176
00:09:37,850 --> 00:09:41,990
The appropriate floating point type to use depends on the nature and range of values you need to work

177
00:09:41,990 --> 00:09:42,940
with in your code.

178
00:09:43,220 --> 00:09:47,650
In situations where either type would be appropriate double is preferred.

179
00:09:47,730 --> 00:09:50,020
OK so by default swift uses double.

180
00:09:50,250 --> 00:09:50,630
OK.

181
00:09:50,630 --> 00:09:53,630
As you can tell it's a 64 bit floating point number.

182
00:09:53,630 --> 00:09:59,330
Very long a float cannot be as big and maybe you think it will I should make the numbers I should say

183
00:09:59,340 --> 00:10:03,010
memory by using a flow and have a double no switch is I optimized under the hood.

184
00:10:03,010 --> 00:10:06,320
And and it recommends that use double overflow and at a given time.

185
00:10:06,320 --> 00:10:09,020
So don't use a float unless you absolutely have to.

186
00:10:09,020 --> 00:10:11,920
Whereas in other languages float is the keyword in swift.

187
00:10:11,940 --> 00:10:14,010
Always use double double double double.

188
00:10:14,420 --> 00:10:15,100
OK.

189
00:10:15,380 --> 00:10:18,980
So just to show you that this is a double by default.

190
00:10:19,130 --> 00:10:26,900
If we do create a float let's say var pi equals three point one for k and then I say Miles Rand equals

191
00:10:27,230 --> 00:10:28,410
pi.

192
00:10:28,630 --> 00:10:30,350
I ran for pi.

193
00:10:30,370 --> 00:10:31,460
See what happens.

194
00:10:33,040 --> 00:10:38,740
Actually this is going to work because the double the flow will convert to double what I meant to do

195
00:10:39,100 --> 00:10:41,380
was pi equals milestone

196
00:10:45,200 --> 00:10:47,010
actually works interchangeably.

197
00:10:47,330 --> 00:10:48,330
News to me.

198
00:10:48,360 --> 00:10:54,890
OK so this is definitely a float though.

199
00:10:54,990 --> 00:10:55,790
Oh that's why.

200
00:10:55,970 --> 00:10:58,400
Ok guys I'm not smoking crack I promise.

201
00:10:58,420 --> 00:11:01,540
This is a it's because it was both a double and like tripping out.

202
00:11:01,540 --> 00:11:02,910
Why is it not working.

203
00:11:02,930 --> 00:11:03,530
OK.

204
00:11:03,530 --> 00:11:05,010
So there you go.

205
00:11:05,510 --> 00:11:05,750
OK.

206
00:11:05,760 --> 00:11:07,700
So pi is a float.

207
00:11:07,700 --> 00:11:08,420
Here we go.

208
00:11:08,420 --> 00:11:10,850
Can I assign a value of type double to type float.

209
00:11:10,850 --> 00:11:13,130
So clearly this is a double.

210
00:11:13,130 --> 00:11:14,410
And clearly this is a float.

211
00:11:14,510 --> 00:11:18,320
So the point I was trying to make is by default it always chooses a double when you use the decimal

212
00:11:18,320 --> 00:11:19,100
points.

213
00:11:19,190 --> 00:11:23,150
And so when you're creating your apps you're only going to really ever use and doubles for the most

214
00:11:23,150 --> 00:11:26,420
part when you're working with numbers which is really cool.

215
00:11:26,780 --> 00:11:35,330
And I encourage you to actually read a whole lot more in this swift book about wherever it went about

216
00:11:35,630 --> 00:11:40,520
all these different things because they has incredibly valuable information incredibly valuable and

217
00:11:40,520 --> 00:11:46,760
it's actually Britain written with the proper keywords because sometimes you may hear an instructor

218
00:11:46,760 --> 00:11:50,360
or somebody talking about programming in general they're not using the right terms or summarizing it

219
00:11:50,360 --> 00:11:54,740
Swift actually in those books they actually use the right keywords and they teach what's going on under

220
00:11:54,740 --> 00:12:00,890
the hood and a lot of cases so those numbers right and you can do a lot of things with numbers.

221
00:12:00,890 --> 00:12:04,060
And we talked in the earlier video about operators.

222
00:12:04,600 --> 00:12:12,010
You're going to use what's called a rith take mad rith math.

223
00:12:12,410 --> 00:12:13,230
Oh my gosh.

224
00:12:13,280 --> 00:12:15,830
I'm sorry I just.

225
00:12:15,830 --> 00:12:18,890
Arithmetic arithmetic.

226
00:12:18,890 --> 00:12:20,600
All right.

227
00:12:20,600 --> 00:12:26,010
Rith metric arithmetic operators.

228
00:12:27,640 --> 00:12:31,400
If you're new to the class and you're wondering like why does he why does he leave some of the stuff

229
00:12:31,400 --> 00:12:34,800
in here like why do we make mistakes and things like that.

230
00:12:34,910 --> 00:12:37,420
And what happened was in the beginning I didn't always do that.

231
00:12:37,430 --> 00:12:40,300
I kind of cleaned up the code and made it look perfect.

232
00:12:40,290 --> 00:12:43,360
Boston's real like you're doing it so perfectly.

233
00:12:43,490 --> 00:12:44,750
You're just so amazing.

234
00:12:44,810 --> 00:12:47,870
I'm never going to be a programmer because you can't do it perfectly.

235
00:12:47,910 --> 00:12:51,240
And I was it guys and gals I'm not doing it perfectly.

236
00:12:51,290 --> 00:12:52,160
This is all edited.

237
00:12:52,160 --> 00:12:55,940
So I started making videos that were real like how programmers really solve problems.

238
00:12:55,970 --> 00:12:58,050
And then everyone's like I can do this.

239
00:12:58,130 --> 00:12:59,700
Mark prizes he's not a robot.

240
00:12:59,720 --> 00:13:02,040
He's a real person who has to figure things out and use his brain.

241
00:13:02,060 --> 00:13:03,080
And that's why we do these things.

242
00:13:03,080 --> 00:13:08,030
That's why these videos are so informal because I pretend that you're sitting here right next to me

243
00:13:08,030 --> 00:13:11,410
in the class so I can actually teach and convey a message to you.

244
00:13:11,420 --> 00:13:13,850
So again if you're new to all this this is how we do it.

245
00:13:13,850 --> 00:13:16,730
All right dev slopes and it's exciting and people love it.

246
00:13:16,730 --> 00:13:20,210
If you hate it I'm sorry I just love it.

247
00:13:20,210 --> 00:13:25,070
OK so arithmetic operators you know and this is just like in math and in high school right or grade

248
00:13:25,070 --> 00:13:25,930
school even right.

249
00:13:25,960 --> 00:13:33,220
You know you get a plus minus divide multiplication and things like that.

250
00:13:33,260 --> 00:13:37,750
And so you can actually you can actually play around with numbers which is kind of cool.

251
00:13:37,750 --> 00:13:45,440
One of my favorite ones is like doing the area of a shape or a rectangle so bar area equals and let's

252
00:13:45,440 --> 00:13:49,240
say lengths of 15 times with 20.

253
00:13:49,270 --> 00:13:50,070
OK.

254
00:13:50,090 --> 00:13:57,430
And we just did multiplication 315 times 20 which is really cool and we can do addition as well.

255
00:13:57,450 --> 00:14:09,220
Var sum equals five plus six bar diff for difference equals 10 minus three 32 10 minus 3.

256
00:14:09,470 --> 00:14:12,990
And so we're doing different operations here which is really cool.

257
00:14:13,070 --> 00:14:14,670
What about division committee division.

258
00:14:14,700 --> 00:14:28,420
Well yes we can we can say let's say 12 divided by groups some division 12 divided by three is four.

259
00:14:28,880 --> 00:14:31,150
But there's one more thing I want to show you.

260
00:14:31,160 --> 00:14:32,950
OK.

261
00:14:33,320 --> 00:14:38,900
What if you said bar divide and we said what is 12 divided by five.

262
00:14:40,710 --> 00:14:43,190
Do you think it's going to be groups.

263
00:14:43,230 --> 00:14:46,540
One equals 12 divided by five.

264
00:14:46,540 --> 00:14:49,360
And again these are just container names for giving them OK.

265
00:14:49,710 --> 00:14:53,900
So wait a minute 12 divided by five is not two words the remainder.

266
00:14:53,900 --> 00:15:00,240
There's got to be a remainder well in swift and pretty much every other programming language division

267
00:15:00,390 --> 00:15:03,400
or the arithmetic operator for division.

268
00:15:03,480 --> 00:15:11,820
This backslash here is only going to do the division and only give you how many times it goes into a

269
00:15:11,820 --> 00:15:12,190
number.

270
00:15:12,210 --> 00:15:14,620
The remainder actually is not going to be provided to you.

271
00:15:14,640 --> 00:15:21,570
So to get the remainder you actually have to use what's called the remainder operator or modulo or modulus.

272
00:15:21,570 --> 00:15:24,120
I've heard people say all kinds of things.

273
00:15:24,280 --> 00:15:29,310
Call it the modulo operators commonly used or the remainder operator that's what Swift calls the remainder

274
00:15:29,310 --> 00:15:30,260
operator.

275
00:15:30,300 --> 00:15:36,590
So the remainder operator is this equals 12 percent sign 5.

276
00:15:36,830 --> 00:15:37,620
OK.

277
00:15:37,920 --> 00:15:40,430
So which is two.

278
00:15:40,440 --> 00:15:44,780
There's two of a remainder OK right so five goes in the 12 two times with the remainder of two.

279
00:15:44,780 --> 00:15:50,650
Let's in fact let's do 13 just to show you that these are different numbers here OK.

280
00:15:51,080 --> 00:15:56,010
So so I wanted to show the full problem OK I could do something like this.

281
00:15:56,010 --> 00:15:59,880
Var result equals.

282
00:15:59,910 --> 00:16:00,860
This is going to be a string right.

283
00:16:00,870 --> 00:16:09,510
So the result of 13 divided by five is OK.

284
00:16:10,230 --> 00:16:13,650
We can use string interpolation here.

285
00:16:13,730 --> 00:16:25,430
Now OK to insert a variable in and we can say Div 1 and I will say dot for the decimal right with the

286
00:16:25,430 --> 00:16:28,500
remainder of.

287
00:16:29,100 --> 00:16:31,550
Not really the dots not really appropriate.

288
00:16:31,710 --> 00:16:41,470
Five is with a remainder of origo and then we'll put in the remainder.

289
00:16:42,030 --> 00:16:48,620
So the result of and divided by five is to with a remainder of three.

290
00:16:48,860 --> 00:16:49,400
OK.

291
00:16:49,650 --> 00:16:51,510
And don't worry if you don't understand all this just yet.

292
00:16:51,510 --> 00:16:53,610
I'm just inserting variables into my string.

293
00:16:53,610 --> 00:16:55,470
Here's the print out to the screen.

294
00:16:55,470 --> 00:16:59,190
So what happens with the remainder operator is it is going to do the division.

295
00:16:59,310 --> 00:17:02,250
But instead of returning the first number it's going returned the remainder.

296
00:17:02,250 --> 00:17:11,140
If there is a remainder and this is a great way to determine what numbers are even or odd even numbers

297
00:17:11,410 --> 00:17:16,930
will have no remainder right so if I wanted to know if number was even or Onslow say bar random number

298
00:17:17,350 --> 00:17:19,090
equals 13.

299
00:17:19,090 --> 00:17:25,750
So we can say if a random number modulo two equals zero.

300
00:17:25,750 --> 00:17:29,880
So the double equal sign is this something is something true or false you know.

301
00:17:29,920 --> 00:17:32,570
Or is this equal to that it's going to give you a boolean value.

302
00:17:32,650 --> 00:17:37,860
So if random number modulo or remainder operator two equals zero.

303
00:17:38,130 --> 00:17:40,480
OK you know we'll print.

304
00:17:40,570 --> 00:17:43,280
This is an even number.

305
00:17:43,900 --> 00:17:45,250
All right.

306
00:17:45,250 --> 00:17:46,740
Else.

307
00:17:46,860 --> 00:17:50,860
Print this is an odd number.

308
00:17:51,660 --> 00:17:52,470
OK.

309
00:17:52,890 --> 00:17:54,180
And so look it's printing up.

310
00:17:54,180 --> 00:17:57,550
This is an odd number but what if we turn this to 12.

311
00:17:57,610 --> 00:17:58,120
OK.

312
00:17:58,210 --> 00:17:59,320
So this is an even number.

313
00:17:59,320 --> 00:18:03,700
So this is something that is very commonly used to determine whether numbers are even or odd.

314
00:18:03,700 --> 00:18:04,570
Is this remainder.

315
00:18:04,570 --> 00:18:05,320
Operator.

316
00:18:05,440 --> 00:18:07,460
So you've done some basic arithmetic.

317
00:18:07,480 --> 00:18:11,400
We've talked about different types here like and double and low.

318
00:18:11,440 --> 00:18:15,300
You can use negative numbers you can use positive numbers.

319
00:18:15,430 --> 00:18:17,270
You can do all kinds of fun things.

320
00:18:17,270 --> 00:18:18,370
All right.

321
00:18:18,640 --> 00:18:22,510
And by the way this right here this is a very operator.

322
00:18:22,510 --> 00:18:25,220
Kind of like what we've talked about in the past.

323
00:18:25,360 --> 00:18:28,580
It's operating on one target here making a negative number here.

324
00:18:28,650 --> 00:18:32,610
Just so you know we'll well tip and trick right there.

325
00:18:32,900 --> 00:18:37,930
So don't worry too much about the NL so if you don't understand that just yet or the string into position

326
00:18:37,930 --> 00:18:42,580
that we used here the point of this lesson is to talk about numbers you can do math operations and of

327
00:18:42,580 --> 00:18:48,820
course order of operations are all followed in swift as well as most other programming languages so

328
00:18:49,140 --> 00:18:51,350
I can save our results.

329
00:18:51,370 --> 00:18:54,150
Two equals let's say 15 times.

330
00:18:54,310 --> 00:18:58,620
Five plus seven divided by three.

331
00:18:58,810 --> 00:18:59,120
All right.

332
00:18:59,170 --> 00:19:06,250
And if I want a five and seven to be done first and then I wanted the result of this to be done next

333
00:19:08,050 --> 00:19:08,860
I could do something like that.

334
00:19:08,860 --> 00:19:16,090
So just like you do in math like in high school the order of operations you know still applies the same

335
00:19:16,090 --> 00:19:18,970
that you would do in math in high school and you can use parentheses just like you would do in high

336
00:19:18,970 --> 00:19:23,130
school math to get the results that you are looking for.

337
00:19:23,140 --> 00:19:24,810
And again this is very foundational.

338
00:19:24,810 --> 00:19:30,130
Every app you've ever used uses math like this when you're swiping your card at a bank and it wants

339
00:19:30,130 --> 00:19:35,160
to deduct money it's got to use math to take money out of your bank account things like that.

340
00:19:35,230 --> 00:19:40,960
So you have now you as a basic foundational thing that you can use the rest of your life as a programmer

341
00:19:41,080 --> 00:19:43,250
and you never know that you'll ever build.

342
00:19:43,700 --> 00:19:45,590
So that's it numbers.

343
00:19:45,670 --> 00:19:48,440
Mark Price heads up slopes dot com.

344
00:19:48,460 --> 00:19:48,950
See you next.
