这是我的简单代码
@Override
public void onClick(View v) {
try {
double price = Double.parseDouble(ePrice.getText().toString());
double percent = Double.parseDouble(ePercent.getText().toString());
double priceValue = price * percent/100.0f;
double percentValue = price - priceValue;
moneyToGet.setText(String.valueOf(priceValue));
moneyToPay.setText(String.valueOf(percentValue));
moneyToGet.setText("" + priceValue);
moneyToPay.setText("" + percentValue);
// catch
} catch (NumberFormatException ex) {
// write a message to users
moneyToGet.setText("");
}
}
});
这是一个简单的百分比计算器代码。
我想要的是避免在我的计算器中使用科学计数法,因为我不想向用户解释什么是科学计数法。
例如如果我想计算100,000,000并削减50%,它应该给我50,000,000> 这给了我 5.0E7 在我的例子中,这对用户没有任何意义。当然,我知道这两个结果都是正确的。 提前致谢。
最佳答案
检查答案 here .你可以写
moneyToGet.setText(String.format("%.0f", priceValue));
关于android - 如何避免双重科学记数法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20813631/