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

Rounding to tenths? [closed]

Asked by 10 years ago

This question already has an answer here:

math.round ?

I want to use math.floor() but it rounds to real numbers. Is there a way I can set it to round tenths not rounding it to real numbers?

0
rounds to integers* rounding to reals would the identity BlueTaslem 18071 — 10y

Marked as Duplicate by adark and Articulating

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Noculus 25
10 years ago

You first multiply your number by 10 round it, then divide by ten again. :)

0
Thanks man you save lifes. YellowoTide 1992 — 10y
Ad
Log in to vote
1
Answered by
jobro13 980 Moderation Voter
10 years ago

I once created a handy function for this;

function Round(Num, Decimals)
    return math.floor((Num)*(10 ^Decimals) + 0.5)/(10^Decimals)
end

In your case, use

Round(x, 1) where x is your number.

Please ask if you would like an explanation :)

0
This won't work exactly as expected for negative numbers, by the way. adark 5487 — 10y