使用 println 无法获得正确的输出格式



如何改变这个数字:5.8774367E-70.00000058774367 ?非常感谢。代码:

float Deal_order = Deal_factor*(float)Order_value;
System.out.println("Deal Order is:" + Deal_order);

花药的问题:我如何在GUI中做同样的事情?

textField_9.setText (Float.toString (Deal_factor));

谢谢你的帮助

使用printf()

System.out.printf("Deal Order is: %.14fn", Deal_order);

点后面的部分(在这个例子中是14)是你的数字的小数位数。

https://docs.oracle.com/javase/tutorial/java/data/numberformat.html

不使用'println',您可以轻松地使用'printf'来格式化输出

System.out.printf("Deal order is: %.15fn", Deal_order );

您可以使用printf设置格式。

试题:

System.out.printf("Deal order is: %.10fn", Deal_order);

对于大的小数位数,可以搜索BigDecimal

最新更新