格式化BigDecimal,无需科学记数法,具有完全精确度 [英] Format BigDecimal without scientific notation with full precision
本文介绍了格式化BigDecimal,无需科学记数法,具有完全精确度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将 BigDecimal
转换为 String
以进行打印,但打印出所有数字而不用科学记数法。例如:
I'd like to convert a BigDecimal
to String
for printing purposes but print out all digits without scientific notation. For example:
BigDecimal d = BigDecimal.valueOf(12334535345456700.12345634534534578901);
String out = d.toString(); // Or perform any formatting that needs to be done
System.out.println(out);
我想得到 12334535345456700.12345634534534578901
已打印。现在我得到: 1.23345353454567E + 16
。
I'd like to get 12334535345456700.12345634534534578901
printed. Right now I get: 1.23345353454567E+16
.
推荐答案
保存 BigDecimal
的精度你需要将值作为字符串
To preserve the precision for a BigDecimal
you need to pass the value in as a String
BigDecimal d = new BigDecimal("12334535345456700.12345634534534578901");
System.out.println(d.toPlainString());
这篇关于格式化BigDecimal,无需科学记数法,具有完全精确度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文