PDA

View Full Version : PHP: Divide with remainders



Dillion & Amanda 4 Life!
06-07-2010, 08:22 PM
<?php

function divide($val1,$val2){
$res = round($val1 / $val2);
if(fmod($val1,$val2) > 0){
$res .= '<sup>r'.fmod($val1,$val2).'</sup>';
}
return number_format($res);
}

echo divide(100,5); // Returns 20
echo divide(100,7); // Returns 14 and a small 2 in the right hand corner.

?>


Just figured this would help people out with getting full division done.

Zero-Affect
06-07-2010, 10:58 PM
Now this is fun since i did avgval people have done some functions, Good on you guys it's always good to submit them to the notes on php.net also.

Karlos94
06-08-2010, 09:27 AM
There is one problem, the way you have formatted it your making it looking powers.. I'd recommend having a look and rethinking how to display it.

Dillion & Amanda 4 Life!
06-08-2010, 05:41 PM
There is one problem, the way you have formatted it your making it looking powers.. I'd recommend having a look and rethinking how to display it.

Fine. I added an "r" next to the remainder.