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

Help with simple math!? Can someone help? It rounds downwards.

Asked by 6 years ago

So i want to do one thing in the future. I wanna round a number to the nearest thousand. I did this test that doesnt work. Help?

local x = 567
local a = 567 / 1000
local rounded = math.floor(a)
print (rounded * 1000)

for some reason it rounds downwards

0
I know now Nilsen84 1 — 6y
0
How would you do to round it to nearest number Nilsen84 1 — 6y
0
If mattscy properly answered your question, be sure to mark his answer as correct! Shawnyg 4330 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago
local number = 567
local rounded = math.floor(number/1000+0.5)*1000
print(rounded)
0
Sorry forgot to multiply by 1000 again, edited. mattscy 3725 — 6y
0
Explain your answer! What did they not do? (Answer, they forgot to add .5 to the number they were flooring) M39a9am3R 3210 — 6y
0
thx guys Nilsen84 1 — 6y
Ad

Answer this question