shin shin - 5 months ago 63
Java Question

Mistake while adding double values in java

I have the following code:

double d1=1000000000000000000.0; //which is equivalent to 1.0e^18
double d2=3434.0;

which prints 1000000000000003460 instead of 1000000000000003434. What is the problem?


@Anthony Pegram is right. If you need such precision use BigDecimal.