Java BigDecimal without E

前端 未结 4 2128
抹茶落季
抹茶落季 2021-01-11 13:38

I have a BigDecimal variable

BigDecimal x = new BigDecimal(\"5521.0000000001\");

Formula:

x = x.add(new BigDecimal(\"-1\")
         


        
4条回答
  •  梦谈多话
    2021-01-11 13:46

    To get a String representation of the BigDecimal without the exponent part, you can use
    BigDecimal.toPlainString(). In your example:

    BigDecimal x = new BigDecimal("5521.0000000001");
    x = x.add(new BigDecimal("-1").
                  multiply(x.divideToIntegralValue(new BigDecimal("1.0"))));
    System.out.println(x.toPlainString());
    

    prints

    0.0000000001
    

提交回复
热议问题