【问题标题】:Displaying value of a double variable without Scientific Notation显示没有科学记数法的双变量的值
【发布时间】: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


【解决方案1】:
Log.d("tag", "" + new BigDecimal(catchBookingQtyDoubleForm * catchRatePerBrickDoubleForm));

【讨论】:

    猜你喜欢
    • 2011-11-21
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    相关资源
    最近更新 更多