Array_To_CSV.php
3 years ago
Currency.php
3 years ago
Device.php
2 years ago
Number_Formatter.php
3 years ago
Option.php
2 years ago
Request.php
2 years ago
Salt.php
3 years ago
Security.php
3 years ago
Singleton.php
2 years ago
String_Util.php
3 years ago
URL.php
3 years ago
WP_Async_Request.php
3 years ago
WordPress_Site_Date_Format_Pattern.php
3 years ago
Number_Formatter.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Utils; |
| 4 | |
| 5 | use DateTime; |
| 6 | class Number_Formatter |
| 7 | { |
| 8 | /** |
| 9 | * Pass in 90 and get back 1:30. Pass in 121 and get back 2:01. |
| 10 | * |
| 11 | * @param int $seconds |
| 12 | * |
| 13 | * @return string |
| 14 | */ |
| 15 | public static function second_to_minute_timestamp(int $seconds) : string |
| 16 | { |
| 17 | $unix_epoch = new DateTime("@0"); |
| 18 | $now = new DateTime("@{$seconds}"); |
| 19 | $interval = $unix_epoch->diff($now); |
| 20 | return $interval->format('%i:%S'); |
| 21 | } |
| 22 | /** |
| 23 | * @param int|float $number |
| 24 | * @param int $decimals |
| 25 | * |
| 26 | * @return string |
| 27 | */ |
| 28 | public static function percent($number, int $decimals = 0) : string |
| 29 | { |
| 30 | if (\class_exists('\\NumberFormatter')) { |
| 31 | $formatter = new \NumberFormatter(\get_locale(), \NumberFormatter::PERCENT); |
| 32 | $formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals); |
| 33 | return $formatter->format($number / 100); |
| 34 | } else { |
| 35 | return \number_format_i18n($number, $decimals) . '%'; |
| 36 | } |
| 37 | } |
| 38 | /** |
| 39 | * @param int|float $number |
| 40 | * @param int $decimals |
| 41 | * |
| 42 | * @return string |
| 43 | */ |
| 44 | public static function decimal($number, int $decimals = 0) : string |
| 45 | { |
| 46 | return \number_format_i18n($number, $decimals); |
| 47 | } |
| 48 | } |
| 49 |