• Post Reply Bookmark Topic Watch Topic
  • New Topic

Number format exception while converting String to double  RSS feed

 
Reshmi Kuttappan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
  • 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..........

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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........
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • 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 $.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!