/** * Rounds a value to the nearest multiple of a target. */ public static float RoundNearest(float v, float target) { target = Math.Abs(target); if (v >= 0) { return(target * FloatMath.Floor((v + 0.5f * target) / target)); } else { return(target * FloatMath.Ceiling((v - 0.5f * target) / target)); } }