Skip to content

Instantly share code, notes, and snippets.

@salmonmoose
Created March 19, 2015 03:58
Show Gist options
  • Save salmonmoose/77120eafb467665f1f98 to your computer and use it in GitHub Desktop.
Save salmonmoose/77120eafb467665f1f98 to your computer and use it in GitHub Desktop.
Round a number up to a significant number of digits.
function ceilToSignificant($number, $figures) {
$digits = ceil(log10($number < 0 ? -$number : $number));
$power = $figures - (int) $digits;
$magnitude = pow(10, $power);
$shifted = ceil($number * $magnitude);
return $shifted / $magnitude;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment