Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialUhunoma Osula
6,414 PointsHow does this make sense
I did 5.6*0.1 which is 0.56 the console answered 0.5599999999999999 I am so confused
2 Answers
Simon Voort
5,682 PointsComputers use binary code, which means they store numbers (and other things) as sequences of 1’s and 0’s. When you write code, it is converted into binary code when your program runs. However, some numbers cannot be exactly represented in binary code, so the computer has to use the closest number it can store. This can happen with floats/decimals. The operands you use are floats and some floats are not exact in binary, so Python uses a slightly different number close to the numbers you gave. It performs the multiplication with those numbers and then rounds the result to the closest number it can store in binary code, in this case .5599999999999999.
To get the answer you expected, you can use the round function, which takes two arguments: the number you want to round, and the number of decimals. For example:
round(5.6*.1, 2) # result: .56
Uhunoma Osula
6,414 PointsThan you that made so much sense