• Post Reply Bookmark Topic Watch Topic
  • New Topic

floats instability  RSS feed

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assign a 0.7f to it, when it is saved off to the database.
It got a 0.6999f in it.
I have tried the following method to no avail

Any ideas?
Thanks
Jack
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"instability" isn't the correct word, inaccuracy is more appropriate. And yes, both float and double have inaccuracies. That's just the way computers and floating point works.

If you want to avoid the inaccuracies use BigDecimal throughout.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at these FAQs (No 20).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!