Skip to content

Instantly share code, notes, and snippets.

@mikemix
Last active May 25, 2025 10:00
Show Gist options
  • Save mikemix/3d9ad3a420e62727d7278de5f297ca3f to your computer and use it in GitHub Desktop.
Save mikemix/3d9ad3a420e62727d7278de5f297ca3f to your computer and use it in GitHub Desktop.
php bcround implementation polyfill for php <8.4
<?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