Reputation: 13161
Is there a easy way to transform 1000000 in 1.000.000? A regex or string format in asp.net, c#
Upvotes: 10
Views: 8020
Reputation: 158319
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 = "."
}));
Upvotes: 13
Reputation: 25063
I think you're asking about culture-specific formatting. This is the Spanish way, for example:
1000000.ToString("N", CultureInfo.CreateSpecificCulture("es-ES"));
Upvotes: 7
Reputation: 11879
Using ToString("N")
after will convert 1000000 to 1,000,000. Not sure about . though
Upvotes: 4
Reputation:
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
Upvotes: 2