+ 1
float in java
I am facing a very weird issue in this simple addition code. The answer of (1.1)+(-1) is coming 0.100000024 https://code.sololearn.com/cihF01qib8v3/?ref=app
1 Answer
+ 4
The reason is float type in Java is not so accurate 32- bit. Instead of float type you can use double or even BigDecimal - it depends on accuracy you need. You can read more about it here: https://stackoverflow.com/questions/27598078/float-and-double-datatype-in-java.
Hope that explanation can help you.