开发者

Separate long numbers by 3 digits

开发者 https://www.devze.com 2022-12-31 02:10 出处:网络
Is there a easy way to transform 1000000 in 1.000.000? A regex or string format in asp.net开发者_运维问答, c#You can use ToString together with a formatting string and a format provider that uses \'.\

Is there a easy way to transform 1000000 in 1.000.000? A regex or string format in asp.net开发者_运维问答, c#


You can use ToString together with a formatting string and a format provider that uses '.' as a group separator and defines that the number should be grouped in 3-digit groups (which is not the case for all cultures):

int number = 1000000;
Console.WriteLine(number.ToString("N0", new NumberFormatInfo()
                                            {
                                                NumberGroupSizes = new[] { 3 },
                                                NumberGroupSeparator = "."
                                            }));


1000000.ToString("N0")


I think you're asking about culture-specific formatting. This is the Spanish way, for example:

1000000.ToString("N", CultureInfo.CreateSpecificCulture("es-ES"));


Using ToString("N") after will convert 1000000 to 1,000,000. Not sure about . though


Use ToString with numeric format string after reading into an integer. I believe the one you are looking for is "N" and its relatives.

MSDN page about numeric format strings: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消