简体   繁体   English

显示带有千位分隔符的整数

[英]Displaying a Integer with thousand seperator

i want to display a integer value with a thousand seperator. 我想显示带有千位分隔符的整数值。 i found following ways: 我发现以下方法:

int i = 0101010101;
Console.WriteLine(i.ToString("N0")); // 101.010.101
Console.WriteLine(i.ToString("#,#"));// 101.010.101

what's the difference / advantage of each? 每个有什么区别/优势?

There is at least one difference. 至少有一个区别。 If you test it with i = 0 , then the "N0" format string outputs 0 , and the "#,#" format string outputs nothing at all. 如果使用i = 0测试,则"N0"格式的字符串将输出0 ,而"#,#"格式的字符串则将什么都不输出。 As the documentation states: 文档所述:

Note that this specifier never displays a zero that is not a significant digit, even if zero is the only digit in the string. 请注意,即使字符串中的唯一数字为零,该说明符也不会显示不是有效数字的零。 It will display zero only if it is a significant digit in the number that is being displayed. 仅当显示的数字中有一个有效数字时,它才会显示零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM