Win a copy of Functional Reactive Programming this week in the Other Languages 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
Bartender
Posts: 1361
14
  • 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
Pie
Posts: 50258
79
  • 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
Posts: 21416
33
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