Introduction
We often want to format a number using format strings, but we face a problem of deciding the format according to the sign of the number (+ve, -ve or zero). This is an easy tip for formatting numbers.
Using the code
Notice the semi-colon in the formatting string, it's used as a separator between different formatting, first part is for positive number formatting, second is for negative number, and the last is for zero formatting.
string formatstring = "+ 0.##; - 0.##; This is zero";
var no1 = 192.15;
var no2 = - 192.15;
var no3 = 0;
Console.WriteLine(no1.ToString(formatstring));
Console.WriteLine(no2.ToString(formatstring));
Console.WriteLine(no3.ToString(formatstring));
Console.Read();