+ 1

5*x

Hi. If I print (5*1.07) I always get 5.35000000005. But why? I mean if I do it with 4, the result is 4.28, and with 6 the result is 6.42. same happens if I use 0.07; 1.06; 1.007

15th Jul 2022, 3:49 PM
Michal SpiĆĄĂĄk
Michal SpiĆĄĂĄk - avatar
3 Answers
+ 7
Hi! Calculating with floats, when coding, is special. Humens work with decimal numbers, computers with binaries. In the conversion between these two number system, there will be losses (round off errors) as we, as coders, need to learn to handle.
15th Jul 2022, 4:08 PM
Per Bratthammar
Per Bratthammar - avatar
+ 5
15th Jul 2022, 4:07 PM
Jayakrishna 🇼🇳
+ 2
Thanks.Did not have a clue about this 😉
15th Jul 2022, 4:39 PM
Michal SpiĆĄĂĄk
Michal SpiĆĄĂĄk - avatar