J2ME text field to double
Is the开发者_高级运维re a way to convert the string from a text field to a double in j2me? And what is the name of the string that comes out of the text field?
You can use Double.parseDouble(String) method for converting string to double:
double d = Double.parseDouble("22.4");
To get text of TextField you can use TextField.getString() method;
String text = TextField.getString();
So:
double d = Double.parseDouble(TextField.getString());
Make a note that floats are only supported on phones that conform to CLDC 1.1, if the phone you are targetting is CLDC 1.0 you will need to use fixed point
you can do this as well
String s = txtField.getText();
double number1 = Double.parseDouble(s);
精彩评论