Code: Select all
$sale = true;
$salePercent = .25;
if ($sale)
{
$price = round($regPrice - ($price * $salePercent), 2);
} else
{
$price = $regPrice;
}
echo $salePrice;Other times I'll get a rounded value like $7.5 (I want it 7.50)
I was thinking of using str_pad(), but from reading the description it wants a desired length of the input number. Some prices will be over $100 (3 digits) which is a different length than say $10 (2 digits). I'm just concerned with padding the decimal places to ensure that $25 becomes $25.00 and $7.5 becomes $7.50.
I need the extra decimals (even if they're zeros) so it can match prices set in a paypal IPN script.
I could do this with a non-elegant solution of strlen() if(), and str_pad(), but surely there must be an easier way to do this?