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

Rounding to 2 decimal places?

Asked by 8 years ago

Hi guys, I feel that the title is self explanatory, but I feel this question is basic but I still cant do it, so any help would be appreciative. I'm making a KDR script:

KDR.Text = ("Kill/Death Ratio: "..(player.PlayerData.Kills.Value/player.PlayerData.Deaths.Value))

Now this works as supposed to, however the number that is given (obviously) is not always a whole number and can sometimes be recurring which is very annoying, so I was wondering if someone can help me round this to 2 decimal places, ~ thx, Bubs

1 answer

Log in to vote
4
Answered by 8 years ago
value = 5.6879685
local num = math.floor(value * 100)/100

Its quite simple, multiply it by 100 to move it two decimal places up, math.floor to cut off numbers in the thousandths place and beyond, then move it back two decimal places to its original place

0
Thanks :) Bubbles5610 217 — 8y
Ad

Answer this question