Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how would i round up instead of down with math.floor?

local num = 10.6

9 comments

0

math.floor(num + 0.5)

0

If this helped, be sure to put [Solved] in the title so that people know you don't need any more help.

0

You can also use string.format to round to any place: local function round(x, n) return tonumber(string.format("%."..n.."f", x)) end

0

Aether, > = math.floor(0.5) = 0, math.ceil(0.5) = 1

0

you're forgetting about ceil

0

Did you actually read my comment...?

0

math.floor(0 + 0.5) -> 0, math.floor(0.2 + 0.5) -> 0, math.floor(0.5 + 0.5) -> 1, and, finally, math.floor(0.9 + 0.5) -> 1.

0

It works exactly as math.round would work if it existed (math.floor(num + 0.5), that is).

0

Did you not read what he wrote,, KDarren12?

1 answer

✓ Accepted answer

You could use math.ceil().

local num = math.ceil()

4 comments

0

That rounds up to 1 even if the number is, say, 0.3. That's not technically rounding.

0

I would downvote this answer, but it's not entirely inaccurate (and there's a chance it is what he was looking for).

0

k whtver

0

It IS the answer to his question. math.ceil() rounds up instead of down like math.floor(). If he asked how to round to nearest number, then that would be a different story.

This discussion is preserved as it was. New answers, comments, and votes are closed.