When I try the below code, I get the output 2 084 001. What could be wrong here? Isn't my format string supposed to override the current culture settings?
decimal v = 2084000.7621m;
System.Console.WriteLine(v.ToString("#,###,###"));
System.Console.ReadLine();
If I modify the code to use ToString("#,###,###", CultureInfo.InvariantCulture)
, I get the expected output, i.e. 2,084,001 but I cannot specify a format provider when I set the DataFormatString property on my data bound controls.
WARNING: When using an escaped literal group separator, as described below in the accepted and other answers, the literal character used is always output, even if it isn't needed, e.g. applying the format string #\,###\,###
to a value of 324
results in an output value of ,,324
.
ThousandsSeparator
set to a space. – Liquor