WEBVTT
00:00:00.030 --> 00:00:01.709
okay in this video we're going to take a
00:00:01.709 --> 00:00:04.049
look at how we use the math dot round
00:00:04.049 --> 00:00:06.779
feature to round a number so one thing
00:00:06.779 --> 00:00:08.429
to note is that math dot round only
00:00:08.429 --> 00:00:10.530
rounds to the nearest whole number so
00:00:10.530 --> 00:00:12.360
let's take a look at this so if I do a
00:00:12.360 --> 00:00:19.430
print statement and I want to print out
00:00:19.430 --> 00:00:22.830
let's say we're going to round ten point
00:00:22.830 --> 00:00:27.150
six okay and I want to round that number
00:00:27.150 --> 00:00:35.790
so I'm gonna say math round ten point
00:00:35.790 --> 00:00:41.340
six okay and when I run this we're going
00:00:41.340 --> 00:00:44.399
to see that it prints out eleven and if
00:00:44.399 --> 00:00:47.120
I were to round ten point four and
00:00:47.120 --> 00:00:50.850
change that to ten point four will see
00:00:50.850 --> 00:00:55.140
that it rounds it down okay so that's
00:00:55.140 --> 00:00:56.550
great but what if I want to round
00:00:56.550 --> 00:01:00.629
something to one decimal place so if I
00:01:00.629 --> 00:01:02.070
want to round something to one decimal
00:01:02.070 --> 00:01:04.260
place I can essentially take my number
00:01:04.260 --> 00:01:07.590
and multiply it out then ground it and
00:01:07.590 --> 00:01:09.390
then divide so let's take a look at how
00:01:09.390 --> 00:01:12.119
this works so let's just say I have a
00:01:12.119 --> 00:01:16.020
number we'll say double numb equals ten
00:01:16.020 --> 00:01:18.840
point three six now I want to round this
00:01:18.840 --> 00:01:25.650
to one decimal place so what I'm going
00:01:25.650 --> 00:01:26.520
to do is I'm going to take my number
00:01:26.520 --> 00:01:29.579
multiply it by ten so a number equals
00:01:29.579 --> 00:01:34.500
number times ten so now at this point my
00:01:34.500 --> 00:01:39.270
number should be 103 point six okay now
00:01:39.270 --> 00:01:40.829
I'm going to round that number so I'm
00:01:40.829 --> 00:01:49.110
gonna say numb equals math round and I'm
00:01:49.110 --> 00:01:52.710
gonna round my number okay so now I
00:01:52.710 --> 00:01:56.040
should have 104 because it's going to
00:01:56.040 --> 00:01:57.890
round it to that nearest whole number
00:01:57.890 --> 00:02:01.200
okay and so then finally I can take that
00:02:01.200 --> 00:02:03.780
final number and I can now divide it by
00:02:03.780 --> 00:02:05.790
ten so I'm going to say number equals
00:02:05.790 --> 00:02:09.599
number divided by ten okay and when I
00:02:09.599 --> 00:02:12.720
print this out I should now see ten
00:02:12.720 --> 00:02:13.890
point four
00:02:13.890 --> 00:02:29.730
so let's go ahead and print that out
00:02:29.730 --> 00:02:36.910
okay so that's mine um there and great I
00:02:36.910 --> 00:02:39.120
see it was rounded to one decimal place
00:02:39.120 --> 00:02:41.319
now what if I want to round it to
00:02:41.319 --> 00:02:42.880
different decimal places I don't want to
00:02:42.880 --> 00:02:45.610
necessarily have this divided by 10 or
00:02:45.610 --> 00:02:47.650
whatever if I want to take and do
00:02:47.650 --> 00:02:49.900
something like round PI to 3 decimal
00:02:49.900 --> 00:02:51.760
places I can do that systematically
00:02:51.760 --> 00:02:54.850
using the math dot pal feature or math
00:02:54.850 --> 00:02:56.830
powers so what I'm going to do is I'm
00:02:56.830 --> 00:02:58.299
going to create a new variable called PI
00:02:58.299 --> 00:03:00.549
and I'm going to just set that equal to
00:03:00.549 --> 00:03:03.280
math dot pi and what I want to do is I
00:03:03.280 --> 00:03:04.900
want to take this variable and multiply
00:03:04.900 --> 00:03:07.480
it by 10 to the third power and so I'm
00:03:07.480 --> 00:03:11.019
going to essentially dumat pi equals pi
00:03:11.019 --> 00:03:17.890
times math.pow 10 to the third okay what
00:03:17.890 --> 00:03:18.850
that's going to do is it's going to
00:03:18.850 --> 00:03:21.430
multiply that essentially by 10 to the
00:03:21.430 --> 00:03:25.510
third power I can then take pi and round
00:03:25.510 --> 00:03:33.250
it so pi equals math.round pi and
00:03:33.250 --> 00:03:35.500
finally I'm going to take pi and divide
00:03:35.500 --> 00:03:37.690
it by the same number I just multiplied
00:03:37.690 --> 00:03:42.269
by so pi equals pi divided by math pow
00:03:42.269 --> 00:03:47.260
ten to the third okay and now I can
00:03:47.260 --> 00:03:52.630
print this out and I will see that I
00:03:52.630 --> 00:03:56.739
have pi rounded to three digits and
00:03:56.739 --> 00:03:58.000
we're going to use this concept of
00:03:58.000 --> 00:04:01.060
multiplying it out and using this value
00:04:01.060 --> 00:04:03.190
here the 3 to get different decimal
00:04:03.190 --> 00:04:06.010
places as we explore how many decimal
00:04:06.010 --> 00:04:08.470
places we need to get the best value of
00:04:08.470 --> 00:04:11.579
our circumference