I would like to know why I get this error. (this is Display log of Eclipse debug)
var
(double) 2.8
tot.getIva()
(java.lang.Double) 0.17
var+tot.get()
(double) 2.9699999999999998
I can not understand why I did not get simply 2.97!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you wanted
2.97, you should have usedBigDecimal.doubles are stored as fractions in binary, not decimal. So3.75, for example, is just stored as2^1 + 2^0 + 2^(-1) + 2^(-2).2.8and0.17cannot be represented exactly as binary fractions, so there’s going to be some rounding error.You may also find this article helpful.