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);
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.