Array_To_CSV.php
3 years ago
Date_Format.php
3 years ago
Exact_Range.php
3 years ago
Number_Formatter.php
3 years ago
Relative_Range.php
3 years ago
Request.php
3 years ago
Salt.php
3 years ago
Security.php
3 years ago
Singleton.php
3 years ago
String_Util.php
3 years ago
Timezone.php
3 years ago
URL.php
3 years ago
WP_Async_Request.php
3 years ago
Number_Formatter.php
23 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Utils; |
| 4 | |
| 5 | class Number_Formatter |
| 6 | { |
| 7 | public static function format($number, $format = 'decimal', $decimals = 0) |
| 8 | { |
| 9 | if ($format == 'percent') { |
| 10 | if (class_exists('\NumberFormatter')) { |
| 11 | $formatter = new \NumberFormatter(get_locale(), \NumberFormatter::PERCENT); |
| 12 | $formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals); |
| 13 | |
| 14 | return $formatter->format($number / 100); |
| 15 | } else { |
| 16 | return number_format_i18n($number, $decimals) . '%'; |
| 17 | } |
| 18 | } else { |
| 19 | return number_format_i18n($number, $decimals); |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 |