Created
April 7, 2024 19:31
-
-
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…
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 | |
| 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