I am getting some numeric text from a JTextField using the JTextField.getText() method. When I use the String returned to instantiate a Double I get a NumberFormatException. Can anyone tell me what I'm doing wrong? If I replace the String variable name with a "99.9" for example, I don't get a problem. My code looks roughly like this : JTextField jt = new JTextField("66.8"); String number = jt.getText(); Double d = new Double(number);
Thanks.
Don Smathers
Ranch Hand
Joined: Mar 04, 2001
Posts: 31
posted
0
I haven't tried this, but it might work: double nbr = Double.parseDouble( number ) ; which should convert "123.456" to 123.456 but, be careful -- if your string is " 123.3" or "cde123.4" the class won't handle the complexity.
Helmut Lerch
Ranch Hand
Joined: Feb 11, 2001
Posts: 48
posted
0
Hi,
Originally posted by Don Smathers: double nbr = Double.parseDouble( number ) ;
If you are using JDK1.1.x you have to use ; since there is no Double.parseDouble(String)