Announcement

Collapse
No announcement yet.

PHP: Divide with remainders

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP: Divide with remainders

    PHP Code:
    <?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.

  • #2
    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.

    Comment


    • #3
      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.
      The best way to make your dreams come true is to wake up.
      - Paul Valery

      Facebook Me? | devianWATCH Me? | Tumblr Me? | Tweet Me?

      Comment


      • #4
        Originally posted by Vortex23','index.php?page=Thread&postID=171538#pos t171538
        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.

        Comment

        Working...
        X