Skip to content

Instantly share code, notes, and snippets.

@fmkoc
Created April 7, 2024 19:31
Show Gist options
  • Select an option

  • Save fmkoc/7b99429a09d881aaf708c3299e222c74 to your computer and use it in GitHub Desktop.

Select an option

Save fmkoc/7b99429a09d881aaf708c3299e222c74 to your computer and use it in GitHub Desktop.
PHP floatceil Function: This Gist provides a floatceil function implemented in PHP, designed to ceiling floating point numbers to a specific decimal precision. Unlike the standard ceil() function which only works on the whole number, floatceil allows for adjusting the precision of the ceiling operation, making it extremely useful for financial c…
<?php
function floatceil($number, $precision=2) {
$significance = 1/pow(10,$precision);
return number_format(ceil($number/$significance)*$significance, $precision, '.', '');
}
/*
Examples:
floatceil(1, 2) -> 1.00
floatceil(1.035, 2) -> 1.04
floatceil(1.031, 2) -> 1.04
floatceil(1.030001, 2) -> 1.04
floatceil(1.03, 2) -> 1.03
etc.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment