• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Number format exception while converting String to double

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
currnecyt = "$0.00";
tempCrntMnthRate += Double.parseDouble(currnecyt);

Am getting a Number format exception as "java.lang.NumberFormatException: For input string: "$0.00""


Please help..........
 
Reshmi Kuttappan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
currnecyt = "$0.00";
tempCrntMnthRate += Double.parseDouble(currnecyt);

Am getting a Number format exception as "java.lang.NumberFormatException: For input string: "$0.00""


Please help..........

 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

From API ,
Throws NumberFormatException - if the string does not contain a parsable double.

$0.00 should be converted to 0.00 before using parseDouble.
 
Reshmi Kuttappan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Balu Sadhasivam wrote:
From API ,
Throws NumberFormatException - if the string does not contain a parsable double.

$0.00 should be converted to 0.00 before using parseDouble.





hey thanks..............I tried it & its working fine........
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you understand why you were getting a Numberformatexception? When you do a parseDouble...it takes a string so the compilation is ok. But during runtime when the number is actually converted, it doesn't get converted to a double because the the format of the number you have passed is not a double but rather a String because of the $.
 
reply
    Bookmark Topic Watch Topic
  • New Topic