BladeOne.php
2 years ago
CSV.php
9 months ago
Calculations.php
2 years ago
Currency.php
8 months ago
Device.php
1 year ago
Device_Cache.php
2 years ago
Dir.php
5 months ago
Format.php
5 months ago
Link_Validator.php
6 months ago
Number_Formatter.php
5 months ago
Obj.php
6 months ago
Request.php
11 months ago
Salt.php
1 year ago
Security.php
1 year ago
Server.php
2 years ago
Singleton.php
2 years ago
String_Util.php
2 years ago
Timezone.php
5 months ago
URL.php
6 months ago
WP_Async_Request.php
1 year ago
Calculations.php
27 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Utils; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class Calculations |
| 7 | { |
| 8 | public static function divide(float $numerator, float $denominator, int $precision = 0) |
| 9 | { |
| 10 | if ($denominator === 0.0 && $numerator > 0) { |
| 11 | return 100; |
| 12 | } elseif ($denominator === 0.0) { |
| 13 | return 0; |
| 14 | } |
| 15 | return \round($numerator / $denominator, $precision); |
| 16 | } |
| 17 | public static function percentage(float $numerator, float $denominator, int $precision = 0) |
| 18 | { |
| 19 | if ($denominator === 0.0 && $numerator > 0) { |
| 20 | return 100; |
| 21 | } elseif ($denominator === 0.0) { |
| 22 | return 0; |
| 23 | } |
| 24 | return \round($numerator / $denominator * 100, $precision); |
| 25 | } |
| 26 | } |
| 27 |