【发布时间】:2015-08-22 13:49:25
【问题描述】:
我有一个简单的计算代码来计算盒子的体积(长 * 宽 * 高):
ActionListener volListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
String L = long.getText();
String W = width.getText();
String H = height.getText();
double parseL = Double.parseDouble(L);
double parseW = Double.parseDouble(W);
double parseH = Double.parseDouble(H);
double volResult = parseL*parseW*parseH;
txtAreaOut.append("Volume : " + volResult + "\n");
long.setText("");
width.setText("");
height.setText("");
}catch(NumberFormatException nfe){
String fault = nfe.getMessage();
infoBox(fault, " " + nfe.getClass());
}
}
};
如果 "volResult" 返回较大的数字,例如 9.0408284742E7, 我想要这样的结果 9.040.828.474...
代码如何?..
【问题讨论】:
-
检查这里,如果你想要逗号,有显示整数和/或格式化数字字符串的答案。 stackoverflow.com/questions/9602444/…
-
这是许多问题的重复,是另一个问题的重复,我什至不知道该选哪个...
标签: java format double number-formatting