This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with DecimalFormat

 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code (which I didn't write) occasionally prints an error like 'price: 7.949999809265137java.lang.NumberFormatException: For input string: ".795E1795E1"'

Anyone know how this could happen?

 
Norm Radder
Ranch Hand
Posts: 732
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post an example that ALWAYS gets the error?
In other words, write some sample code that sets the value of price to cause the error. Then run that simple program and copy/paste all of the output here.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope nobody is using that code in real life; it is bad enough using double values for money, but float with its lower precision is even worse.
 
Paul Clapham
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides, it is a very roundabout way of rounding a number to two decimal places.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic