/** * 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.ceil((v - 0.5f * target) / target); } }
/** * 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.ceil((v - 0.5f * target) / target); } }