private float ToFloat(double value) { var result = (float)value; if (float.IsPositiveInfinity(result)) { result = float.MaxValue; } else if (float.IsNegativeInfinity(result)) { result = float.MinValue; } return result; }