public static double roundNearest ( double v , double target ) { target = Math . abs ( target ) ; if ( v >= 0 ) { return target * Math . floor ( ( v + 0.5f * target ) / target ) ; } else { return target * Math . ceil ( ( v - 0.5f * target ) / target ) ; } }
Rounds a value to the nearest multiple of a target .