gpt4 book ai didi

java - 使用 DecimalFormat 将科学记数法转换为 java 中的固定记数法

转载 作者:行者123 更新时间:2023-11-30 04:47:16 25 4
gpt4 key购买 nike

有没有办法将Java中的科学记数法转换为固定记数法。目前我有以下代码:

DecimalFormat dfmt=new DecimalFormat("######:#######");
print(dfmt.format((new BigDecimal((Math.pow(10,-3)*3000),MathContext.Decimal64)).stripTrailingZero()));

上面的代码确实将科学计数法转换为固定计数法,但是如果结果大于零,则忽略小数位。在上面的例子中,它打印 3;而不是 3.0

最佳答案

使用模式0.0:

BigDecimal d = new BigDecimal("12345678901234567890"); // large integer
System.out.println(new DecimalFormat("0.0").format(d));

输出(在我的语言环境中):

12345678901234567890.0

关于java - 使用 DecimalFormat 将科学记数法转换为 java 中的固定记数法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10686493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com