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.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; |
| 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 |