Add phpunit tests folder, fix in Math method floorp when precision was larger then number length

This commit is contained in:
Clemens Schwaighofer
2021-10-29 11:12:23 +09:00
parent 58e61b8902
commit 4c859ada01
12 changed files with 178 additions and 12 deletions

View File

@@ -31,6 +31,11 @@ class Math
*/
public static function floorp(float $number, int $precision = -2): float
{
// if precision is requal or larger than the number length,
// set precision to length -1
if (abs($precision) >= strlen((string)$number)) {
$precision = (strlen((string)$number) - 1) * -1;
}
$mult = pow(10, $precision); // Can be cached in lookup table
return floor($number * $mult) / $mult;
}