I run the following code, but did not expect that result..
public class SampleDemo {
public static void main(String args[]) {
System.out.println(10.00 - 9.10);
}
}
I am getting o/p as 0.9000000000000004
Why is it so?
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.
This is because decimal values can’t be represented exactly by float or double.
One suggestion : Avoid float and double where exact answers are required. Use BigDecimal, int, or long instead
Using int :
Using BigDecimal :