使用DecimalFormat在Java中将科学记数法转换为固定记数法

时间:2012-05-21 13:46:46

标签: java

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

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

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

1 个答案:

答案 0 :(得分:2)

使用模式0.0

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

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

12345678901234567890.0