phpdivisionreminders

ATM machine example in PHP


I need to write a PHP script that calculates the No. of time it divides a number and reminder too. Lets say $amount=9200; if I divide this with 5000 then output should be 5000: 1 times and Reminder: 4200. I think i need to use $n=$amount%5000; But I got only reeminder not the no. of times it divides.

Thanks!!


Solution

  • This is well-known as the euclidean division : http://en.wikipedia.org/wiki/Euclidean_division

    $amount = 9200;
    $divide = 5000;
    $times = floor($amount/$divide);
    $reminder = $amount%$divide;
    
    echo "$amount = $times times $divide plus $reminder";