java 格式化字符串“%,d”和“%,d”
java format string "%,d" and "%, d"
为什么是
public static void main(String arr[]){
System.out.println("[" + String.format("%, d",1000000000) + "]");
}
写成[ 1,000,000,000]
,在数字前面加上space?
此外,与作为格式说明符的“%,d”相比,“%,d”是什么意思?
"%, d"
表示您正在打印 1 space,然后是带逗号的整数 ([ 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
为什么是
public static void main(String arr[]){
System.out.println("[" + String.format("%, d",1000000000) + "]");
}
写成[ 1,000,000,000]
,在数字前面加上space?
此外,与作为格式说明符的“%,d”相比,“%,d”是什么意思?
"%, d"
表示您正在打印 1 space,然后是带逗号的整数 ([ 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