Jonathan
Jonathan

Reputation: 986

Point Formula based on a dynamic amount

I'm trying to create a dynamic point system based off of how much money is available in a bank account. For instance, if someone has 20 points and we have 100 dollars in the bank account, I want the formula to return something along the lines of $1.

I don't care too much about the ratio at this point - more about the formula to get there.

So far, I've come up with a handful of different formulas,

$val = (1 / $this->bank) * $amt; //goes the wrong way
$val = ($amt / $this->bank) * 5000; //isn't a good ratio

Assume val is the amount you can get with all the points, bank is how much is in the bank, and $amt is the amount of points the user has.

A gentle nudge in the right direction would be helpful!

Thanks!

Upvotes: 1

Views: 101

Answers (2)

lanzz
lanzz

Reputation: 43158

$bank * ($points / 2000)

This satisfies your test case, giving 1 for $bank = 100 and $points = 20.

Upvotes: 1

Benoit
Benoit

Reputation: 680

Saying $percentage is the percentage you want between your points and the bank account amount to have 1$ reward, you will have:

$percentage = 20;
$val = $amt * $this->bank / ($percentage * 100);

Upvotes: 1

Related Questions