Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to format 1700 to 1'700 and 1000000 to 1'000'000 in c#?

I like to format all numbers like in math. is there a predefined function or is that just possible with substring and replace?

edit: my culture is de-ch

Best regards

like image 985
Marc Avatar asked Jan 20 '10 10:01

Marc


2 Answers

Try this

int input = Convert.ToInt32("1700");
string result = String.Format("{0:##,##}", input);

Or this

Console.WriteLine(1700.ToString("##,##", new NumberFormatInfo() { NumberGroupSeparator = "'" })); 
like image 64
Faisal Avatar answered Sep 24 '22 14:09

Faisal


var numformat = new NumberFormatInfo {
                   NumberGroupSeparator = "'",
                   NumberGroupSizes = new int[] { 3 },
                   NumberDecimalSeparator = "."
                };
Console.WriteLine(1000000.ToString("N",numformat));
like image 43
adrianm Avatar answered Sep 26 '22 14:09

adrianm