I'd like to String.Format
a decimal so that it has both thousand separators and forced decimal places (3).
For example:
Input:
123456,12
78545,8
Output:
123.456,120
78.545,800
I have tried
String.Format("{0:0.0,000}", input);
but this only gives the thousand separators but doesn't force the decimal places.
In a custom numeric format string a period (.
) is used for a "localized decimal separator". Ie. even if your current locale uses a comma as a decimal separator you should use a period in a format string. Similarly comma (,
) is used for the localised thousands separator.
As your format puts the comma after the period things are going to get confused (thousands separators don't apply after the decimal point).
So try:
String.Format("{0:#,##0.000}", input);
(Using #
for digits to only include if input
is large enough.)
String.Format("{0:N3}", input)
See the N format specifier
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With