Page 1 of 1

Best way to figure out a percent markup.

Posted: Tue Apr 11, 2006 9:25 am
by Red Blaze
Ok, I gotta know what's the best way to figure out a mathematical function. I thought I figured it out, but it comes out different all the time. Here's what I did.

Code: Select all

$unitprice = '5.00';
$markup = 20;
$markup = $unitprice * ".$markup";
$unitprice = $unitprice + $markup;
echo $unitprice;
$markup is 20, for 20%. Which is why I added the period in front in line 3 for the 2nd $markup. I wanted to increase 5.00 by 20%, is what I'm trying to say. I dunno if that's the correct way, or if there's a better way. Help is well appreciated, thank you!

~RB

Posted: Tue Apr 11, 2006 9:34 am
by JayBird
Just multiply the unit price by 1.2 to add 20% on

Posted: Tue Apr 11, 2006 10:03 am
by pickle

Code: Select all

$unitprice = '5.00';
$markup = 20;
$marked_up_price = (float)$unitprice * (($markup + 100)/100);

echo $marked_up_price
Do you have to declare $unitprice as a string? Take off the quotes and you won't have to convert it back to a float.