Closed Thread Icon

Preserved Topic: Converting types in Java Pages that link to <a href="https://ozoneasylum.com/backlink?for=20930" title="Pages that link to Preserved Topic: Converting types in Java" rel="nofollow" >Preserved Topic: Converting types in Java\

 
Author Thread
butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 04-27-2001 03:16

Yea, it's me again. I need to know if there is a way to convert a piece of a string, to a double. The program I have to write requires that the user input a temperature, but it has to end with a letter (i.e. 98.6F or 32C). Because of the letter ending I read the input from the keyboard as a string and not a double. Now I want to convert the number part of the string to a double, but I don't seem to be able to. I tried :

degrees = (double)degreesString;

with degrees being declaired as a double already. When I compile I get this:

C:\jdk1.3\demo\mine\TempConverter.java:20: inconvertible types
found : java.lang.String
required: double
degrees = (double)degreesString;
^

As always, your help is appreciated.

You guys are worth your weight in gold.

Thanks

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 04-27-2001 05:50

double x = Double.parseDouble(String);

You may want to try and catch the shit, see exception handling for that.

-mage-

« BackwardsOnwards »

Show Forum Drop Down Menu