For example
round(18.5)
gives me 18
round(19.5)
gives me 20
I want the output of round(18.5)
to be 19
Asked
Active
Viewed 255 times
-1
1 Answers
0
math.floor(x + 0.5)
will always round .5
up.

Barmar
- 741,623
- 53
- 500
- 612
-
um, what's the $x? It says SyntaxError: invalid syntax – ppwater Nov 04 '20 at 04:17
-
Sorry, was thinking PHP – Barmar Nov 04 '20 at 04:21
-
Oh, I see. and by the way, you have to define x first if you are going to execute this code – ppwater Nov 04 '20 at 04:23
-
1Yes, I was trying to give an answer that would work for something other than just 18.5. – Barmar Nov 04 '20 at 04:24