String.Format consider locale or not?
You want to use CultureInfo:
value.ToString("N", new CultureInfo("vn-VN"));
Using String.Format
:
String.Format(new CultureInfo("vi-VN"), "N", value);
Since you're in Hanoi (from profile), I used Vietnam's code, which is vn-VN
.
This works. The formatted value is 123.456,789
which is correct per es-ES
IFormatProvider iFormatProvider = new System.Globalization.CultureInfo("es-ES");
var value = 123456.789001m;
string s = value.ToString("#,##0.000", iFormatProvider);
string s2 = string.Format(iFormatProvider, "{0:#,##0.000}", value);
FormattableString fs = $"{value:#,##0.000}";
string s3 = fs.ToString(iFormatProvider);
Note that the ,
and .
are using a 'standard' en-US style, but .ToString()
and string.Format()
with a format provider does the right thing.