Below extension method converts a value/object to double and if its not convertible then returns 0.0;
//use it like: string s=4.5; double d = s.ToDouble();
public static double ToDouble(this object source)
{
double val = 0;
if (source != null)
{
string str = Convert.ToString(source);
if (! string.IsNullOrEmpty(str))
{
double.TryParse(str, out val);
}
}
return val;
}
9:30 AM
Rajesh Rolen
0 comments:
Post a Comment