Skip to content

Commit 7a1b23a

Browse files
committed
upsome methods
1 parent 3d2c6b5 commit 7a1b23a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Math.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use function abs;
66
use function ceil;
77
use function floor;
8+
use function round;
9+
use const PHP_ROUND_HALF_UP;
810

911
/**
1012
* Class Math
@@ -42,4 +44,26 @@ public static function abs($value): int
4244
{
4345
return (int)abs($value);
4446
}
47+
48+
/**
49+
* @param int|float $value
50+
* @param int $precision
51+
* @param int $mode
52+
*
53+
* @return float
54+
*/
55+
public static function round($value, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): float
56+
{
57+
return (float)round((float)$value, $precision, $mode);
58+
}
59+
60+
/**
61+
* @param int|float $value
62+
*
63+
* @return int
64+
*/
65+
public static function roundInt($value): int
66+
{
67+
return (int)round((float)$value);
68+
}
4569
}

0 commit comments

Comments
 (0)