can't figure out how to correct a rounding issue
Posted: Wed Dec 02, 2009 8:30 pm
Trying to pull out the percentage of a discounted price. Anyone have any ideas as to how to get correct amount in both situations?
Code: Select all
$total = 1.00; // original price
$disc = .80; //price after applying a 20% discount
echo number_format(100-(($disc / $total)*100), 0) . '%'; //results in correct 20%
$total = .28;
$disc = .22;
echo number_format(100-(($disc / $total)*100), 0) . '%'; //unwanted results - shows up as 21%