So I have a GUI that displays a person's stats, such as the battles they've won, the battles they've lost, and the tournaments they've won. One of these stats is the win/loss ratio, which is the person's wins divided by their losses to show the rate at which they usually win. However, I want this stat to always have two decimal places behind it. I've managed to restrict it to where there are always a maximum of two decimal places in the instance that the quotient is an irrational number, but let's say the wins are 5 and the losses are 1 - that would mean that the ratio would come out at 5. But I'd rather it say 5.00 instead. How can I do that? You might say to just put a string that says ".00" at the end, but what if it has one decimal place behind it already? In this case, I'd have to make a script that detects how many decimal places are behind a number, which I have no clue how to do. I've looked across the wiki for an answer and I have not come across one so far. Do any of you have a clue how to do this?
This is my script.
function addComma(n) --This is to add a comma to the numbers in the event that it goes into the thousands.
local f,k = n
while (true) do
f,k = string.gsub(f,"^(-?%d+)(%d%d%d)","%1,%2")
if (k == 0) then break end
end
return f
end
while wait(.1) do
battle = script.Parent.BattleStat
blost = script.Parent.BlostStat
ratio = script.Parent.RatioStat
tourn = script.Parent.TournStat
cash = script.Parent.CashStat
player = script.Parent.Parent.Parent.Parent.Parent.Parent
stat = player:WaitForChild("leaderstats")
battle.Text = "Battles Won: " ..addComma(stat.Battles.Value)
blost.Text = "Battles Lost: " ..addComma(player.Blost.Value)
r1 = math.floor((stat.Battles.Value/player.Blost.Value)*100) --Rounds it to the nearest hundredth.
if player.Blost.Value == 0 and stat.Battles.Value ~= 0 then
ratio.Text = "Battle Wins to Losses Ratio: " ..stat.Battles.Value --In the event that it has to divide by 0, the number won't come out as infinity.
else
ratio.Text = "Battle Wins to Losses Ratio: " ..r1/100
end
tourn.Text = "Tournaments Won: " ..addComma(stat.Tournaments.Value)
cash.Text = "Current Cash: $" ..addComma(stat.Cash.Value)
end

1 comment
Thank you so much! I don't know how I missed that article!