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).ToStri ng("f;;#"));
// expected: 123.40 actual: f
MessageBox.Show ((123.40m).ToSt ring("f;;#"));
// expected: 123.4 actual: f
MessageBox.Show ((123.4m).ToStr ing("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).ToStri ng("f;;#"));
// expected: 123.40 actual: f
MessageBox.Show ((123.40m).ToSt ring("f;;#"));
// expected: 123.4 actual: f
MessageBox.Show ((123.4m).ToStr ing("f;;#"));
// OK: expected: empty actual: empty
MessageBox.Show ((0m).ToString( "f;;#"));
}
}
Comment