This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes addition accuracy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "addition accuracy" Watch "addition accuracy" New topic

addition accuracy

Jason Hocker
Ranch Hand

Joined: Jul 23, 2003
Posts: 132
Why does this return the value 55296.19000000006? How can I get 55296.19?

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Floating point numbers usually don't have exact representations. When you print out a double, you can use the DecimalFormat class.
Joe Vahabzadeh
Ranch Hand

Joined: Jan 05, 2005
Posts: 140
I think the only case where you're guaranteed 100% accuracy is when the fractional parts of the values involved can be represented by sums of negative powers of 2.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41178
Point #20 in the JavaBeginnersFaq covers this.

Ping & DNS - my free Android networking tools app
It is sorta covered in the JavaRanch Style Guide.
subject: addition accuracy
Similar Threads
JTextField InputVerifier
The Same Doubt Again
Sorting array & parsing
How to read this Generics method
double value round off