0

I have a program that creates a GUI with three text fields in it, and two of these fields is supposed to accept a numeric value. I want to know how to get the numeric entries and store them in a variable for further calculations please.
I know how to get the string value entered into the one field, you just need to code,
String varname = txt1.getText();
and I was hopig for something similar for number values, a double to be specific, as there does not seem to be any .getDouble(); available??
If someone could advise me on this, I would be forever in your debt, and thanks in advance!!

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by bguild
0

You are looking for Double.parseDouble(String text), a static method of the java.lang.Double class, one of the subclasses of java.lang.Number. There are many similar methods such as Integer.parseInt, Float.parseFloat, Long.parseLong, and Byte.parseByte.

They all expect the string that you provide to contain exactly a numeral that you want to convert into a number. If they find anything else, they will throw a NumberFormatException and you should be prepared to deal with that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.