- round: documentation ( source)
<?php
class Calculator {
/**
* Calculate the discount percentage
*/
function getDiscount($price=0, $sale=0)
{
$difference = $price-$sale;
$discount = ($difference/$price) * 100;
if($discount>0) {
return $discount;
}
}
}
$calculator = new Calculator();
echo $calculator->getDiscount(23,24);
if($calculator->getDiscount(23,24)==null){ echo 'No discount'; }
echo round(3.4);