Created
February 11, 2019 15:46
-
-
Save Alir3z4/705a03413d81ad1f45980db65725e132 to your computer and use it in GitHub Desktop.
Will format the given number by $precision and separated by $separator.
This file contains 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 | |
/** | |
* numberFormatPrecision | |
* | |
* Will format the given number by $precision and separated by $separator. | |
* | |
* @param string|int|float $number | |
* @param int $precision | |
* @param string $separator | |
* @return string | |
*/ | |
function numberFormatPrecision($number, $precision = 2, $separator = '.') | |
{ | |
$numberParts = explode($separator, $number); | |
$response = $numberParts[0]; | |
if (count($numberParts) > 1) { | |
$response .= $separator; | |
$response .= substr($numberParts[1], 0, $precision); | |
} | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment