如果
double d = 1.999e-4
我希望输出结果为0.0001999。
我该如何做?
如果
double d = 1.999e-4
我希望输出结果为0.0001999。
我该如何做?
NumberFormat formatter = new DecimalFormat("###.#####");
String f = formatter.format(d);
NumberFormat
类的子类,以了解更多细节。我猜BigDecimal类中有一个叫做toPlainString()
的方法。
举一个例子,如果BigDecimal是1.23e-8,则该方法返回0.0000000124。
BigDecimal d = new BigDecimal("1.23E-8");
System.out.println(d.toPlainString());
double d = 1.999e-4;
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(7);
System.out.println(nf.format(d));
请查看NumberFormat
的方法文档,以您希望的方式格式化您的double
。
DecimalFormat
是NumberFormat
的特例,因为它的构造函数说明,我认为您在此情况下不需要其功能。如果您感到困惑,请查看它们的文档。使用NumberFormat
的工厂方法getInstance()
方便您操作。
System.out.printf("%1$.10f", d);
请看一下
java.text.DecimalFormat
并且
java.text.DecimalFormatSymbols