Forum Moderators: coopster

Message Too Old, No Replies

Subtracting percentages

         

dkin

6:24 pm on May 4, 2005 (gmt 0)

10+ Year Member



I would imagine this is fairly easy to do but I am unaware of how to do it.

I would like an equation like this

$money = rand(5,8) * 5;

then I would like to make that number, for example "25" to become a percent and subtract that amount from another number, so my question is how do I subtract 25% from say 100.

sned

7:49 pm on May 4, 2005 (gmt 0)

10+ Year Member



To turn your random number into a percentage, just divide by 100 ...

25/100 = .25 = 25%

Now the question is, do you want to subtract 25% of a number from the same number?

Something like 100 - 25% of 100? Which would be 100 - 25.

You could do that with something like :

$new_number = $orig_number - ($orig_number * $percentage);

Of course .. I could just be missing what you want to do by a loooong ways :)

-sned

ergophobe

11:37 pm on May 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



same as sned, but a little more compact:

$money = (1 - (rand(5,8) / 20)) * money;