Last active
August 29, 2015 14:04
-
-
Save tannerhodges/1b67a51186d98e3650a1 to your computer and use it in GitHub Desktop.
Rounds value up to next quarter integer
This file contains 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 | |
/** | |
* Rounds value up to next quarter integer | |
* @param mixed $n | |
* @return float | |
*/ | |
function roundUpToQuarter($n) | |
{ | |
if ( ! is_numeric($n)) { return $n; } | |
if ($n == 0) { return null; } | |
$n = (float) $n; | |
$n *= 1000; | |
$x = 250; | |
if ($n % $x !== 0) { $n = round(($n + ($x / 2)) / $x) * $x; } | |
$n /= 1000; | |
return number_format($n, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment