java J2ME 文本字段加倍
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1995611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
J2ME text field to double
提问by benjamin239
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?
有没有办法将字符串从文本字段转换为 j2me 中的双精度值?从文本字段中出来的字符串的名称是什么?
采纳答案by JCasso
You can use Double.parseDouble(String) method for converting string to double:
您可以使用 Double.parseDouble(String) 方法将字符串转换为双精度:
double d = Double.parseDouble("22.4");
To get text of TextField you can use TextField.getString() method;
要获取 TextField 的文本,您可以使用 TextField.getString() 方法;
String text = TextField.getString();
So:
所以:
double d = Double.parseDouble(TextField.getString());
回答by kgutteridge
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
请注意,只有符合 CLDC 1.1 的手机才支持浮点数,如果您的目标手机是 CLDC 1.0,则需要使用定点
回答by daddycardona
you can do this as well
你也可以这样做
String s = txtField.getText();
double number1 = Double.parseDouble(s);

