double d = 1000000000138719341D;
System.out.print(Double.valueOf(d).longValue());
The printed result is
1000000000138719360
Why is it different? And how do I get the correct result?
double d = 1000000000138719341D;
System.out.print(Double.valueOf(d).longValue());
The printed result is
1000000000138719360
Why is it different? And how do I get the correct result?
From the docs:
double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.