Jump to content
MakeWebGames

PHP: Divide with remainders


Recommended Posts

<?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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...