Separate long numbers by 3 digits
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
精彩评论