Problem:
Java Floating Point Problem,
there is a problem with the binary representation of certain floating point numbers which could mess up your calculations.
Occurence:
While making a Android application which could add and subtract numbers, where I was using float variables.
Solution:
Using
BigDecimal with the
String constructor solved my problem, other solutions provided by other sources on the internet didn't match my requirements.
Note:
- Pay attention that you use the String constructor
- BigDecimal is slower in calculations that float types
Sources:
http://www.daniweb.com/software-development/java/threads/109784