You're using "#.##"
as your format string, and #
means "show a digit if it's significant". If you always want to show two digits, you should use "0.00"
as your pattern. See the documentation for custom numeric format strings for more details.
Sample code:
using System;
class Test
{
static void Main()
{
Show(0m); // 0.00
Show(0.123m); // 0.12
Show(123.456m); // 123.46
Show(-123.456m); // -123.46
}
static void Show(decimal value)
{
Console.WriteLine(value.ToString("0.00"));
}
}
Note that this uses the current culture for formatting, so you could end up with "123,46" for example. If you always want a dot for the decimal separator, specify CultureInfo.InvariantCulture
as the format provider.