Add three new methods to the Basic class

- fceil: hack for float numbers that not properly round up
- floorp: roundown(number, precision): eg 48756, -2 => 48700
- initNumeric: set variable to 0 if not numeric
This commit is contained in:
Clemens Schwaighofer
2018-12-19 11:17:20 +09:00
parent 98e16e6143
commit 754c2edbd2

View File

@@ -2275,6 +2275,38 @@ class Basic
return str_replace(array("\r", "\n"), $replace, $string);
}
// METHOD: fceil
// PARAMS: number, round decimals (default 10)
// RETURN: correct ceil number
// DESC : some float numbers will be rounded up even if they have no decimal entries
public function fceil($number, $precision = 10)
{
return ceil(round($number, $precision));
}
// METHOD floorp
// PARAMS: number, round to
// RETURN: floor number but with tround to
// DESC : eg 48767 with -2 -> 48700
public function floorp($number, $precision = -2)
{
$mult = pow(10, $precision); // Can be cached in lookup table
return floor($number * $mult) / $mult;
}
// METHOD: initNumeric
// PARAMS: any value
// RETURN: if not numeric, sets to 0, else returns value already set
// DESC : inits input to 0, if value is not numeric
public function initNumeric($number)
{
if (!is_numeric($number)) {
return 0;
} else {
return $number;
}
}
// METHOD: setFormToken
// PARAMS: session name, if not set then default is form_token
// RETURN: form token