Need some help with some quick math

I have an obsession with automating everything in my code and I am currently trying to automate the DevProduct sales UI.

Normally the ratio of Coins to Robux is 2/1 so 100 Coins costs 50 Robux. What I am having trouble with is the UI; for example the says “25% More!” but how do I get this percentage increase?

For Example: 125 / 50 = 2.5 so the percentage would be 25% right? I did the math in my head to determine it but I need a formula for the code.

Since the ratio is 2 I can probably do.
math.abs(((4 - 2.5) / 2) - 1) = .25

But this seems way more complicated than it has to be.

Does anyone have any ideas? Thanks and have a good one!

100 * 0.25 + 100, defoultAmount * percentage in decimals + defoultAmount

I’m not sure what you are referring to with the 125/50, are you trying to go from coinsGiven/price → ratio?

If this is the case, you would need to do (coinsGiven / price) / defaultRatio - 1. This would give you .25 which you can multiply by 100 to get 25
where:

  • coinsGiven = amount of currency given
  • price = cost of currency in robux
  • defaultRatio = normal currency pricing (100/50 or 2)

If the opposite is the case, @nuttela_for1me’s answer seems correct.

But what if the percentage in decimals is what I am trying to find?

Say
The default amount is 100
And the new amount is 125
Both are sold for 50 Robux

I think I figured it out (New Amount / Old Amount) - 1

(125 / 100) - 1 = .25