Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
Sun's Java Developer Connection had a goog Tech Tip on this issue. The essence of the problem is this: a double is stored in binary floating-point representation. There is no exact floating-point representation for some numbers (like 0.1), so the real double value is the closest floating-point value to 0.1. In binary, this value is 1001100110011001100110011001100110011001100110011010. The class java.math.BigDecimal uses a non-floating-point representation for numbers. So, this value:
is exactly equal to 0.1 Use BigDecimal in your program, and you'll get the expected behavior.
Replies: |
Sponsored Links
|