aspose file tools
The moose likes Beginning Java and the fly likes Number format exception while converting String to double Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Number format exception while converting String to double" Watch "Number format exception while converting String to double" New topic
Author

Number format exception while converting String to double

Reshmi Kuttappan
Greenhorn

Joined: May 26, 2009
Posts: 17
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

Joined: May 26, 2009
Posts: 17
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

Joined: Jan 01, 2009
Posts: 874


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

Joined: May 26, 2009
Posts: 17
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

Joined: Jul 15, 2009
Posts: 536
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 $.


[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Number format exception while converting String to double
 
Similar Threads
Exception Question
Java (Precision Problem)
Number formatting
problem with printing double value as 0.00 ?
"DecimalFormat"