Created
January 11, 2016 04:55
-
-
Save softon/3dfe45157933ce2c6726 to your computer and use it in GitHub Desktop.
A simple function to calculate percentage without checking the divisor for zero. Also includes precision point.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* A simple function to calculate percentage without checking the divisor for zero. | |
* Also includes precision point | |
* | |
* @param $got | |
* @param $out | |
* @param int $precision | |
* @return float|int | |
*/ | |
function calcPercentage($dividend, $divisor, $precision=0){ | |
if($divisor<=0){ | |
return 0; | |
} | |
return round($dividend/$divisor*100,$precision); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment