I came accross a weird problem, I want to do some basic math checks. I have read to avoid floating numbers so I decided to multiply my math values with 10000, because my value can be between 0.9 and 0.0025.
Everything works correct except for two values: 0.56 and 0.57:
var result = 0.57 * 10000
The outcome is: 5699.999999999999, I hoped for 5700!! And 0.56 is also going wrong but all the other values are correct, what am I missing here?
Your choices in Javascript (indeed, in most languages) are integers or floating point numbers. If you write “0.57” you are forcing it into the world of floating point, where accuracy is limited.
If you want absolute accuracy, you’ll need to work exclusively in integers.