1 00:00:00,000 --> 00:00:00,330 2 00:00:00,330 --> 00:00:02,700 >> SPEAKER 1: Suppose I'd like to write a program that prints out a float, 3 00:00:02,700 --> 00:00:05,700 specifically the result of dividing 1 by 10. 4 00:00:05,700 --> 00:00:08,830 Well, my first instincts would be to write this program as follows. 5 00:00:08,830 --> 00:00:18,160 Float f equals 1 divided by 10, and then print f of percent .1f, thereby 6 00:00:18,160 --> 00:00:22,270 signifying that I'd like to print a float to one decimal place, 7 00:00:22,270 --> 00:00:26,490 backslash n comma f. 8 00:00:26,490 --> 00:00:28,270 Let's now compile this program. 9 00:00:28,270 --> 00:00:32,980 Make float 0 dot slash float 0. 10 00:00:32,980 --> 00:00:34,140 >> Well, that's not quite right. 11 00:00:34,140 --> 00:00:40,210 I'm quite sure that 1 divided by 10, or 1/10 is not 0.0, but 0.1, and yet 12 00:00:40,210 --> 00:00:42,820 here I'm seeing on the screen 0.0. 13 00:00:42,820 --> 00:00:43,860 What's going on? 14 00:00:43,860 --> 00:00:47,790 Well, it turns out that in c, if you divide an int by an int, 15 00:00:47,790 --> 00:00:49,090 you get back an int. 16 00:00:49,090 --> 00:00:54,810 And so even though 1 divided by 10 is indeed 0.10, 0.1 cannot fit in an int, 17 00:00:54,810 --> 00:00:58,930 and so what c does is it truncates, or throws away everything after the 18 00:00:58,930 --> 00:01:01,770 decimal place, thereby leaving us with just 0. 19 00:01:01,770 --> 00:01:04,989 >> But then, of course, with print f, we specify that we'd like to print f to 20 00:01:04,989 --> 00:01:09,260 one decimal place, and so that 0 is displayed as 0.0. 21 00:01:09,260 --> 00:01:11,540 Well, clearly this is a problem that needs a solution. 22 00:01:11,540 --> 00:01:14,025