• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

addition accuracy

 
Jason Hocker
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does this return the value 55296.19000000006? How can I get 55296.19?

 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Point #20 in the JavaBeginnersFaq covers this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic