要显示带有千位分隔符的数字,请设置逗号标志。
System.out.printf( "%,d\n",78567);
以上结果。
78, 567
让我们检查更大的数字。
System.out.printf( "%,d\n", 463758);
以上结果。
463,758
public class Demo {
public static void main( String args[] ) {
System.out.printf( "%,d\n", 95647 );
System.out.printf( "%,d\n", 687467 );
System.out.printf( "%,.2f\n", 7546.21 );
System.out.printf( "%,.2f\n", 463758.787 );
System.out.printf( "%,.2f", 123456.5 );
}
}输出结果
95,647 687,467 7,546.21 463,758.79 123,456.50