Why is
public static void main(String arr[]){
System.out.println("[" + String.format("%, d",1000000000) + "]");
}
将其写为[ 1,000,000,000 ]
,数字前面有一个空格?
另外,与格式说明符“%,d”相比,“%, d”的含义是什么?
Why is
public static void main(String arr[]){
System.out.println("[" + String.format("%, d",1000000000) + "]");
}
将其写为[ 1,000,000,000 ]
,数字前面有一个空格?
另外,与格式说明符“%,d”相比,“%, d”的含义是什么?
"%, d"
意味着你将打印 1 个空格,然后是带逗号的整数([1,000,000,000]
)
"%,d"
意味着你将打印带逗号的整数([1,000,000,000]
)
"%d"
意味着你将打印不带逗号的整数([1000000000]
)
当您运行以下代码行时
// extra space in front with number formatted
System.out.println(String.format("%, d",1000000000));
// number formatted with ,
System.out.println(String.format("%,d",1000000000));
// just number
System.out.println(String.format("%d",1000000000));
OUTPUT:
1,000,000,000
1,000,000,000
1000000000