5

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

Marc
  • 2,659
  • 3
  • 34
  • 41

5 Answers5

6

Try this

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

Or this

Console.WriteLine(1700.ToString("##,##", new NumberFormatInfo() { NumberGroupSeparator = "'" })); 
Faisal
  • 4,054
  • 6
  • 34
  • 55
3
var numformat = new NumberFormatInfo {
                   NumberGroupSeparator = "'",
                   NumberGroupSizes = new int[] { 3 },
                   NumberDecimalSeparator = "."
                };
Console.WriteLine(1000000.ToString("N",numformat));
adrianm
  • 14,468
  • 5
  • 55
  • 102
0

Try this:

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

Or

NumberFormatInfo likeInMath = new NumberFormatInfo()
{
    NumberGroupSeparator = "'"
};
Console.WriteLine(1000000.ToString("#,##0", likeInMath));
Rubens Farias
  • 57,174
  • 8
  • 131
  • 162
0

use int.ToString() and an iFormatProvider.

also take a look here msdn.

gingerbreadboy
  • 7,386
  • 5
  • 36
  • 62
0

I always Use this format

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

so You can use it in

 int input = Convert.ToInt32("100000000");  
 string result = String.Format("{#,##0;#,##0'-';0}", input);
Nasser Hadjloo
  • 12,312
  • 15
  • 69
  • 100