Floating point arithmetic not producing exact results [duplicate]

If you need exact decimal values, you should use java.math.BigDecimal. Then read “What Every Computer Scientist Should Know About Floating-Point Arithmetic” for the background of why you’re getting those results.

(I have a .NET-centric article which you may find easier to read – and certainly shorter. The differences between Java and .NET are mostly irrelevant for the purposes of understanding this issue.)

Leave a Comment