如何输出Double与小数点后20位? [英] How to output the Double with 20 decimal places?
本文介绍了如何输出Double与小数点后20位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
Double d = 1.000000000000000000000000000000001;
System.out.println(d);
上面的代码打印1.0,但我想要d存储整个值。
所需的输出是1.0000000000000000000000000000000000001
The code above prints 1.0 but i want d to store entire value. desired output was 1.000000000000000000000000000000001
我关心的是如何将这个值存储在双倍?
有没有办法增加一个双人可以存储的小数?
请指导我
my concern is how to store this value in double? is there any way to increase the decimals a double can store? please guide me
推荐答案
您需要使用 BigDecimal 。
示例: BigDecimal test = new BigDecimal(1.000000000000000000000000000000001); p>
Example:
BigDecimal test = new BigDecimal("1.000000000000000000000000000000001");
System.out.println(test);
使用 double $ c不能表示相同的原因$ c>是
double
有64位。
这篇关于如何输出Double与小数点后20位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文