Sunday, August 2, 2009

How can I cast a String variable value into a double variable in Java Programming?

I spent all day to figure this out %26amp; I get an error when trying to compile. I am trying to write a code using Java Programming. The code bascially gets a value from the user and does some calculation and prints out the result. The value that I get from the user should be String and I should cast it into double variable, how do I do this? Thanks a bunch!!

How can I cast a String variable value into a double variable in Java Programming?
hello, for java programmers it is very much easy. u r also trying to become a good java programmer. keep it up.


consider the following code segment.





double dTot;


String s = "11316500.00"


double dTot=Double.parseDouble(s);





in this way you can convert the string to the double variable.


Note: you can convert the double basic data type to the object as


Double dObj = new Double(s);


this can be used at the situation when you want to convert the double value to the object.


__Vasantha kumar
Reply:Try using a Double object with the method


static Double parseDouble (String s)


with s being the string you wish to convert


No comments:

Post a Comment