How Can I Make Sure That This Win/Loss Ratio Always Has Two Decimal Places Behind It?
Asked by
8 years ago Edited 8 years ago
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.
04 | f,k = string.gsub(f, "^(-?%d+)(%d%d%d)" , "%1,%2" ) |
05 | if (k = = 0 ) then break end |
11 | battle = script.Parent.BattleStat |
12 | blost = script.Parent.BlostStat |
13 | ratio = script.Parent.RatioStat |
14 | tourn = script.Parent.TournStat |
15 | cash = script.Parent.CashStat |
16 | player = script.Parent.Parent.Parent.Parent.Parent.Parent |
17 | stat = player:WaitForChild( "leaderstats" ) |
18 | battle.Text = "Battles Won: " ..addComma(stat.Battles.Value) |
19 | blost.Text = "Battles Lost: " ..addComma(player.Blost.Value) |
20 | r 1 = math.floor((stat.Battles.Value/player.Blost.Value)* 100 ) |
21 | if player.Blost.Value = = 0 and stat.Battles.Value ~ = 0 then |
22 | ratio.Text = "Battle Wins to Losses Ratio: " ..stat.Battles.Value |
24 | ratio.Text = "Battle Wins to Losses Ratio: " ..r 1 / 100 |
26 | tourn.Text = "Tournaments Won: " ..addComma(stat.Tournaments.Value) |
27 | cash.Text = "Current Cash: $" ..addComma(stat.Cash.Value) |