public static double ToInteger(double d)
{
// if it's NaN
if (d != d)
{
return +0.0;
}
if (d == 0.0 || d == double.PositiveInfinity || d == double.NegativeInfinity)
{
return d;
}
if (d > 0.0)
{
return Math.Floor(d);
}
else
{
return System.Math.Ceiling(d);
}
}