How to make a percentage?

my script is working properly, thanks to everyone who helped me

1 Like

Yeah. Parenthesis matter very much, don’t forget them. I ran Blokav’s code through the Lua demo page and it worked as intended.

local a = 1
local b = 30

local c = math.floor((a-1)/(b-1) * 100)

print(c) -- 0

The only problem is that the number isn’t accurate because a = 15 results in 48 where it should be resulting in 50.

This could probably be solved by him either adding a final stage as a “Winner’s” section like in classic obbies, or restructuring the game such that the player’s Stage number represents the last stage they have completed, rather than the one they are currently on. That way players would start at zero and when completing the game, they would be on a non-counted “end-game” stage, while their Stage Value would remain at 30. Offsetting the values would not be needed with that system.

The optimal way of truncating a decimal and do what you want is via string.format.
The format %.2f should achieve your goal, since it specifies a float with 2 decimal numbers.

Completed.Text = string.format('%.2f%% of obby completed', Percentage)

Note that for the literal % to show, I escaped it with a double %%.

1 Like

it worked, thanks :smile:
30character

I can’t seem to replicate that, what does your code look like?

I thought it was going wrong but I’m sorry
is that my number is small so always give an integer without decimal I tested changing the values to a high value and it worked

if you want to see my game … here he are
https://www.roblox.com/games/4665225618/Ultimate-Obby-Beta

2 Likes

Thanks, I try to remember that :+1:

How can you do it with ContentProvider.RequestQueueSize

Or you can use tonumber(), it still works if there’s no string letters.