Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Number Format Exception (double to Long)  RSS feed

 
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
 
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
 
author & internet detective
Posts: 39286
745
Eclipse IDE Java VI Editor
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!