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

Is there a way to round a number up if it's over 0.5?

Asked by 8 years ago

I know of math.ceil and math.floor but those round the number up and down no matter what the decimal is. Is there a way to round a number to it's closest integer?

1 answer

Log in to vote
6
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

You want

  • 0.49 --> 0
  • 0.51 --> 1
  • 1.49 --> 1
  • 1.51 --> 2
  • 2.49 --> 2
  • 2.51 --> 3

This looks a lot like math.floor. Each one on the left is just off by 0.5.

In fact, the answer is just

math.floor(x + 0.5)

0
But it says OVER .5! Vezious 310 — 8y
0
Thank you BobserLuck 367 — 8y
Ad

Answer this question