没有E的Java BigDecimal [英] Java BigDecimal without E

查看:231
本文介绍了没有E的Java BigDecimal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个BigDecimal变量

I have a BigDecimal variable

BigDecimal x = new BigDecimal("5521.0000000001");

公式:

x = x.add(new BigDecimal("-1")
      .multiply(x.divideToIntegralValue(new BigDecimal("1.0"))));

我想删除整数部分,以获得值 x =( 0.0000000001),但我的新值是1E-10而不是0.0000000001。

I want to remove the integer part, to get the value x = ("0.0000000001"), but my new value is 1E-10 and not the 0.0000000001.

推荐答案

要获得 String 表示 BigDecimal 而没有指数部分,您可以使用

< a href =http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#toPlainString%28%29 =noreferrer> BigDecimal。 toPlainString() 。在您的示例中:

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());

打印

0.0000000001

这篇关于没有E的Java BigDecimal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆