Last active
May 25, 2025 10:00
-
-
Save mikemix/3d9ad3a420e62727d7278de5f297ca3f to your computer and use it in GitHub Desktop.
php bcround implementation polyfill for php <8.4
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 | |
if (! function_exists('bcround')) { | |
/** | |
* @param numeric-string $num | |
* @param value-of<\RoundingMode::*> $mode | |
* @return numeric-string | |
*/ | |
function bcround(string $num, int $precision, int $mode = \RoundingMode::HalfAwayFromZero): string { | |
return \bcadd((string) \round((float) $num, $precision, $mode), '0', $precision); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment