Convert String to double in Java
如何将一个String
(如"12.34"
转换为Java中的double
?
You can use Double.parseDouble()
to convert a String
to a double
:
String text = "12.34"; // example String
double value = Double.parseDouble(text);
For your case it looks like you want:
double total = Double.parseDouble(jlbTotal.getText());
double price = Double.parseDouble(jlbPrice.getText());
如果在将字符串解析为十进制值时遇到问题,则需要将数字中的“,”替换为“。”。
String number = "123,321";
double value = Double.parseDouble( number.replace(",",".") );
double d = Double.parseDouble(aString);
这应该将字符串aString转换为双d。
链接地址: http://www.djcxy.com/p/3554.html上一篇: 如何检查字符串是否是数字(浮点数)?