1 00:00:00,000 --> 00:00:00,330 2 00:00:00,330 --> 00:00:01,830 >> DAVID MALAN: So how can we solve this problem? 3 00:00:01,830 --> 00:00:05,310 Well, the easiest way is just to avoid ints altogether, and instead define 4 00:00:05,310 --> 00:00:06,960 one float by a float. 5 00:00:06,960 --> 00:00:12,460 Specifically, let's change 1 to 1.0 and 10 to 10.0, and then save this 6 00:00:12,460 --> 00:00:14,380 file as floats1.c. 7 00:00:14,380 --> 00:00:20,270 Let's now compile it with make floats1, and then run it with floats1. 8 00:00:20,270 --> 00:00:22,590 And now, I indeed see 0.1. 9 00:00:22,590 --> 00:00:25,540 >> There's another way we could solve it, and that's using casting. 10 00:00:25,540 --> 00:00:29,750 Casting is the process of converting one data type to another, assuming it 11 00:00:29,750 --> 00:00:31,130 makes sense to do so. 12 00:00:31,130 --> 00:00:34,370 In this case, what I could do is go back to the version of code where I'm 13 00:00:34,370 --> 00:00:40,050 dividing one in int by 10 in int, but I could explicitly tell the compiler 14 00:00:40,050 --> 00:00:43,990 that I want to treat 1 as though it's a float, even though it's an int, and 15 00:00:43,990 --> 00:00:48,270 I'd like to treat 10 as a float, even though it, too, is an int. 16 00:00:48,270 --> 00:00:51,760 >> In reality, I could get away with just casting one of these to a float, 17 00:00:51,760 --> 00:00:55,350 because if you divide a float by an int, or an int by a float, C will 18 00:00:55,350 --> 00:00:57,550 return to you a floating point value. 19 00:00:57,550 --> 00:01:01,150 But in this case, for good measure, I'll convert both to floats, recompile 20 00:01:01,150 --> 00:01:06,380 my program with make floats1, then run it with dot slash floats1, 21 00:01:06,380 --> 00:01:08,770 and I also see 0.1. 22 00:01:08,770 --> 00:01:10,983