作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法将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/
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我是一名优秀的程序员,十分优秀!