I have the following code:
double d1=1000000000000000000.0; //which is equivalent to 1.0e^18
double d2=3434.0;
System.out.println(d1+d2);
which prints 1000000000000003460 instead of 1000000000000003434. What is the problem?
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.
@Anthony Pegram is right. If you need such precision use BigDecimal.