C# ToString("#.00") removes my first value [closed]
I pass 0,00 to ToString("#.00")
and it gives me .00
instead while i need it to be 0.00
.
Solution 1:
Yes, that's working as intended. As per the documentation, the #
format specifier means:
Replaces the "#" symbol with the corresponding digit if one is present; otherwise, no digit appears in the result string.
Note that no digit appears in the result string if the corresponding digit in the input string is a non-significant 0. For example, 0003 ("####") -> 3.
If you want a result of 0.00
, use a format string of "0.00"
.
The 0
format specifier is documented (in the summary table):
Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.
There are more details in the specific sections for the "#" custom specifier and the "0" custom specifier.