How to format 1700 to 1'700 and 1,000,000 to 1'000'000 in C #?

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

edit: my de-ch culture

Regards

+5
source share
5 answers

try it

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

Or that

Console.WriteLine(1700.ToString("##,##", new NumberFormatInfo() { NumberGroupSeparator = "'" })); 
+6
source
var numformat = new NumberFormatInfo {
                   NumberGroupSeparator = "'",
                   NumberGroupSizes = new int[] { 3 },
                   NumberDecimalSeparator = "."
                };
Console.WriteLine(1000000.ToString("N",numformat));
+3
source

:

Console.WriteLine(1000000.ToString("#,##0").Replace(
    CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "'"));

NumberFormatInfo likeInMath = new NumberFormatInfo()
{
    NumberGroupSeparator = "'"
};
Console.WriteLine(1000000.ToString("#,##0", likeInMath));
0

 "#,##0;#,##0'-';0"

 int input = Convert.ToInt32("100000000");  
 string result = String.Format("{#,##0;#,##0'-';0}", input);
0

All Articles