Floating point values can be used for efficiently representing values in a much wide range than integer values could. However, it comes at a price: some values cannot be represented exactly (because they are stored binary) Every negative power of 10 for example (0.1, 0.01, etc.)
If you want exact results, try not to use floating point arithmetic.
Of course sometimes you can't avoid them. In that case, a few simple guidelines may help you minimize roundoff errors:
- Don't subtract nearly equal values. (0.1-0.0999)
- Add or multiply the biggest values first. (100*10)* 0.1 instead of 100*(10*0.1)
- Multiply first, then divide. (14900*10.8)/100 instead of 14900*(10.8/100)
- If exact values are available, use them instead of calculating them to get 'prettier' code