Why does 0.ToString("#.##") return an empty string instead of 0.00 or at least 0?

user960567 picture user960567 · Jan 25, 2012 · Viewed 87.5k times · Source

Why does 0.ToString("#.##") return an empty string? Shouldn't it be 0.00 or at least 0?

Answer

Rich O'Kelly picture Rich O'Kelly · Jan 25, 2012

# in the string format indicate that the value is optional. If you wish to get the output 0.00 you need the following:

0.ToString("0.00");

See here for the custom numeric formats that can be passed to this method.