Round 3.385 to 5 ??

Hi there,
I want to round a number float to its closest multiple of 5.

So, say I have a number of 3.338. I would want to round it to 5. If I had a number of 7.89, I would want to round to 10 and so on.

??
Thanks!

static public float RoundBy(float value, float increment = 5f) {

    if (increment <= 0f)
        throw new UnityException(“Increment must be above 0!”);
   
    return Mathf.Round(value / increment) * increment;

}
1 Like