运行 ❯
获取您自己的
Java
服务器
×
更改方向
更改主题,深色/浅色
访问 Spaces
public class Main { public static void main(String[] args) { double myNumber = 123456.78; String result; // Default result = String.format("%f", myNumber); System.out.println(result); // Two decimal digits result = String.format("%.2f", myNumber); System.out.println(result); // No decimal digits result = String.format("%.0f", myNumber); System.out.println(result); // No decimal digits but keep the decimal point result = String.format("%#.0f", myNumber); System.out.println(result); // Group digits result = String.format("%,.2f", myNumber); System.out.println(result); // Scientific notation with two digits of precision result = String.format("%.2e", myNumber); System.out.println(result); } }
123456.780000
123456.78
123457
123457.
123,456.78
1.23e+05