Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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#

like image 983
HasanG Avatar asked May 17 '10 09:05

HasanG


People also ask

How many different numbers can you make with 3 digits?

If what you want are all possible three digit numbers with no repetition of the digits then you have 10 choices for the first digit, you have 9 choices for the 2nd digit, and you have 8 choices for the 3rd digit giving you 10x9x8 = 720 in all.


1 Answers

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 = "."
                                            }));
like image 88
Fredrik Mörk Avatar answered Sep 22 '22 05:09

Fredrik Mörk