private float RoundToEven(float value) { int result = ((int)value / 2) * 2; return result < value ? result + 2 : result; }