Is there 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?
+1
A:
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());
JCasso
2010-01-03 17:36:18
`valueOf()` returns a Double object. In Java 5+ that can be auto-unboxed to a `double`. In J2ME this autoboxing doesn't work, so your second line of code won't compile (even in Java 5+ it does unnecessary work and `parseDouble()` should be prefered, when a `double` is needed).
Joachim Sauer
2010-01-03 17:47:24
Right. Thank you.
JCasso
2010-01-03 18:05:42
A:
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
kgutteridge
2010-01-03 21:13:52
Luckily enough CLDC 1.0 is ancient and mostly gone. CLDC 1.1 isn't the most powerful either, but at least it's got the basics.
Joachim Sauer
2010-01-03 23:29:14
true, about 9% of the market according to getjarhttp://stats.getjar.com/statistics/world/gJavaCLDCVer/j2me_cldc_1_0just worth being aware of!
kgutteridge
2010-01-04 17:21:19