Skip to content

Instantly share code, notes, and snippets.

@tahafarooqui
Last active October 11, 2020 16:49
Show Gist options
  • Save tahafarooqui/60f472dc4f347d9b4945b181d37ee5c7 to your computer and use it in GitHub Desktop.
Save tahafarooqui/60f472dc4f347d9b4945b181d37ee5c7 to your computer and use it in GitHub Desktop.
Modulo (%) Function in PHP
<?php
$price = 1000;
$mod = 8.5;
//1000 * 2% = 80
//OR
//1000 % 8 = 80
echo get_modulo($price,$mod); //Ans 80
//Modulo Function
function get_modulo($price,$mod){
$chip_2 =(floor(log10($price)-2)); //1
$chip_2 = (($chip_2 > 0) ? $chip_2: 1); //1
return (($price/ ($chip_2 *100))* ($chip_2 * $mod));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment