1

Possible Duplicate:
Use a custom thousand separator in C#

I want a string format to format my numbers like this:

Input: 1000 Ouput: 1 000.00
Input: 10000 Output: 10 000.00 
Input: 100000 Output: 100 000.00
Community
  • 1
  • 1

4 Answers4

4

Perfectly working as per you need no need of extra formating

String.Format("{0:# ###.00}", 40000);
output - "40 000.00"
String.Format("{0:# ###.00}", 400000);
output - "400 000.00"
String.Format("{0:# ###.00}", 4000);
output - "4 000.00"

Check Blogpost about this : Format Number To Display

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
1

This will work

String.Format("{0:### ### ### ###.##}", 10000.00)

Result:

"  10 000.00"

You will need to trim the result to remove the extra spaces

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Trevor Pilley
  • 16,156
  • 5
  • 44
  • 60
1

You can do this using NumberFormatInfo class. look at the sample code.

NumberFormatInfo numberFormatInfo = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();          
numberFormatInfo.NumberGroupSeparator = " ";

int a = 1000;

Console.WriteLine(a.ToString("n", numberFormatInfo)); // 1 000.00
Trevor Pilley
  • 16,156
  • 5
  • 44
  • 60
Seminda
  • 1,745
  • 12
  • 15
0

Here you go friend:

var formatInfo = new NumberFormatInfo();
formatInfo.CurrencyGroupSeparator = " ";
formatInfo.CurrencySymbol = string.Empty;

Console.WriteLine(1000.ToString("C", formatInfo));
Console.WriteLine(10000.ToString("C", formatInfo));
Console.WriteLine(100000.ToString("C", formatInfo));
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232