我正在制作一个简单的应用,实际上是我在Android上的第一次尝试。
预期结果
代码
protected void operation(char ope){
double num1 = Double.parseDouble(txtNum1.getText().toString());
double num2 = Double.parseDouble(txtNum2.getText().toString());
double resultMulti = 0;
switch (ope) {
case '*':
resultMulti = num1 * num2;
long a3=(long)resultMulti;
if (resultMulti-a3 <= 0)
txtMultiResult.setText(a3 + "");
else
txtMultiResult.setText(String.format("%.2f",resultMulti));// without E but will be converted to Mobile Language
// txtMultiResult.setText(resultMulti+""); // with E
// txtMultiResult.setText(String.valueOf(resultMulti));// With E
// txtMultiResult.setText(Double.toString(resultMulti));// with E
imm.hideSoftInputFromWindow(btnMulti.getWindowToken(),0);
break;
}
}
答案 0 :(得分:0)
如何在Locale.ENGLISH
内使用String.format()
?如下所示:
txtMultiResult.setText(String.format(Locale.ENGLISH, "%.2f", resultMulti));