A
Andrus
How to create format string for decimal data type
which shows blank for zero and default format otherwize ?
I tried format string "f;f;#" but this shows f for nonzero numbers.
Andrus.
using System.Windows.Forms;
class AppMainEntry
{
static void Main()
{
// Expected: 0.40 actual: f
MessageBox.Show((0.40m).ToString("f;;#"));
// expected: 123.40 actual: f
MessageBox.Show((123.40m).ToString("f;;#"));
// expected: 123.4 actual: f
MessageBox.Show((123.4m).ToString("f;;#"));
// OK: expected: empty actual: empty
MessageBox.Show((0m).ToString("f;;#"));
}
}
which shows blank for zero and default format otherwize ?
I tried format string "f;f;#" but this shows f for nonzero numbers.
Andrus.
using System.Windows.Forms;
class AppMainEntry
{
static void Main()
{
// Expected: 0.40 actual: f
MessageBox.Show((0.40m).ToString("f;;#"));
// expected: 123.40 actual: f
MessageBox.Show((123.40m).ToString("f;;#"));
// expected: 123.4 actual: f
MessageBox.Show((123.4m).ToString("f;;#"));
// OK: expected: empty actual: empty
MessageBox.Show((0m).ToString("f;;#"));
}
}