File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with DecimalFormat

 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • 0
  • 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: 707
3
  • 0
  • 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: 47300
52
  • 0
  • 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: 20206
26
MySQL Database
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic