【发布时间】:2017-05-05 10:19:59
【问题描述】:
我有两个数据类型为 double 的变量,当我将这些变量相乘时,它们以科学形式返回结果,但我的要求是以正常的人类可读形式显示结果。 例如: 当我将 9854795 和 8.9 相乘时,它返回结果为 8.77076755E7 而不是 87707675.5
这是我计算值的函数:
private void calculatingTotalPaymentAmount() {
if (editTextBookingQuantity.getText().toString().equals(""))
{
editTextBookingQuantity.setError("Enter Booking Quantity to calculate Total Payment Amount");
return;
} else if (editTextRatePerBrick.getText().toString().equals(""))
{
editTextRatePerBrick.setError("Enter Rate Per Brick to calculate Total Payment Amount");
return;
} else {
//MathContext mc = new MathContext(4); // 4 precision
final double catchBookingQtyDoubleForm = Double.parseDouble(editTextBookingQuantity.getText().toString());
final double catchRatePerBrickDoubleForm = Double.parseDouble(editTextRatePerBrick.getText().toString().trim());
final double totalPaymentAmount = (catchBookingQtyDoubleForm * catchRatePerBrickDoubleForm);
//bg3 = bg1.multiply(bg2, mc);
//BigDecimal newValue = totalPaymentAmount.setScale(0, RoundingMode.DOWN);
editTextTotalPaymentAmount.setText(""+totalPaymentAmount);
}
}
【问题讨论】:
-
double totalPaymentAmount 将其更改为 BigDecimal 并检查
标签: android double scientific-notation