Created
June 15, 2020 03:47
-
-
Save rnstux/28f70162d3a380f71251955ad5cc76b2 to your computer and use it in GitHub Desktop.
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 | |
$importe = 32887.76 * (10.6666 / 100); | |
echo $importe; | |
echo "\n"; | |
echo floor($importe * 10000) / 10000; | |
echo "\n"; | |
echo money_format_rounded('%!i', $importe); | |
echo "\n"; | |
function money_format_rounded($format, $number, $maxPrecision = 2, $roundingType = \PHP_ROUND_HALF_UP) | |
{ | |
$strlen = strlen($number); | |
if ($strlen === 0) { | |
return money_format($format, $number); | |
} | |
$length = $strlen - strrpos($number, '.') - 1; | |
if ($length <= 0) { | |
return money_format($format, $number); | |
} | |
$rounded = $number; | |
for ($i = --$length; $i >= $maxPrecision; $i--) { | |
$rounded = round($rounded, $i, $roundingType); | |
} | |
return money_format($format, $rounded); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment