I want to be able to format any decimal number as I want. Specifically I want to be able to control:
- the number of decimals
- the decimal separator
- the thousand separator
I have tried to do that
var nfi = new NumberFormatInfo();
nfi.NumberDecimalDigits= 4; <----- for point 1
nfi.NumberDecimalSeparator = "@"; <----- for point 2
nfi.NumberGroupSeparator = "^"; <----- for point 3? or
nfi.PerMilleSymbol= "#"; <----- for point 3?
and then I have applied it:
but for some reasons I can't get to have what I expect.
If I look here it seems that it applies to integers?
And also this answer is not helping.

The formatting properties
NumberDecimalDigits,NumberDecimalSeparator,NumberGroupSeparatorandPerMilleSymboldo not apply to all format strings. To determine their applicability you need to check the docs:NumberDecimalDigits: The NumberDecimalDigits property is used with the "F" and "N" standard format strings without a precision specifier in numeric formatting operations.NumberDecimalSeparator: The NumberDecimalSeparator property is used with the "E", "F", "G", "N", and "R" standard format strings to define the symbol that separates integral from fractional digits.It also used by the "." custom specifier.
NumberGroupSeparator: The NumberGroupSeparator property is used with the "N" standard format string to define the symbol that separates groups of integral digits.It is also used by the "," custom specifier.
PerMilleSymbol: The string assigned to the PerMilleSymbol property is included in the result string when a numeric value is formatted with a format string that includes the "‰" .Since, as noted in the doc remarks for
ToString(IFormatProvider):Only
NumberDecimalSeparatorapplies in this format. You need to pass formats for which you the other options are implemented to see their effect. For instance:Results in:
Demo fiddle here: https://dotnetfiddle.net/81HXz9