• Post Reply Bookmark Topic Watch Topic
  • New Topic

Number Format Exception (double to Long)  RSS feed

 
Chris Cornelius
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an issue with trying convert a double to a Long value. I need to convert the double to Long so that it can be stored in a bean of type Long. Here is the code snippet:



I am getting the following exception:

java.lang.NumberFormatException: For input string: "1230.45"


What am I missing?

Thanks in advance.

Chris
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What am I missing?

Long does not include decimals. If that's what you want, you can cast a double to a long and chop off the decimal :
 
Chris Cornelius
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christope,

So it looks like my options are to change the bean type
to either a string or double to keep the decimal intact.

Chris
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!