Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I round a number up or down to a multiple of a certain number?

Asked by 10 years ago

I've been trying to write a function that rounds a number to the multiple of 4 with the least absolute distance from the number. How do I do this?

I honestly have absolutely no clue how to do this, please help me.

1 answer

Log in to vote
0
Answered by 10 years ago

You can use this simple script :)

function Round(Number,Nearest)
    return math.floor(Number/Nearest + 0.5)*Nearest
end

Round(321,4)
0
Sweet, thanks! xolbStudios 127 — 10y
2
Please provide an explanation with your answers. https://scriptinghelpers.org/help/how-post-good-questions-answers Perci1 4988 — 10y
Ad

Answer this question