ToString
Returns a formatted string on a nullable double
Source
/// <summary>
/// Returns a formatted double or emtpy string
/// </summary>
/// <param name="t">double or null</param>
/// <param name="format">double formatstring </param>
/// <returns></returns>
public static string ToString(this double? t, string format)
{
if (t != null)
{
return t.Value.ToString(format);
}
return "";
}
Example
double? pi = null;
string s = pi.ToString("0.00"); //s = ""
pi = Math.Pi;
s = pi.ToString("0.00"); //s = 3.14