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
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
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
This will work
String.Format("{0:### ### ### ###.##}", 10000.00)
Result:
" 10 000.00"
You will need to trim the result to remove the extra spaces
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
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));