From 189a9ca158de86d11e9399ffc64331d9da67fd1f Mon Sep 17 00:00:00 2001 From: Hassan Zahirnia Date: Sat, 27 May 2023 23:39:23 +0330 Subject: [PATCH 1/3] Improve convertCount function --- src/Overlook.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Overlook.php b/src/Overlook.php index 6081887..4805d87 100644 --- a/src/Overlook.php +++ b/src/Overlook.php @@ -70,18 +70,12 @@ public function formatRawCount(string $number): string public function convertCount(string $number): string { if (config('overlook.should_convert_count')) { - $formattedNum = match (true) { - strlen($number) >= 13 => bcdiv($number, '1000000000000', 1) . 'T', - strlen($number) >= 10 => bcdiv($number, '1000000000', 1) . 'B', - strlen($number) >= 7 => bcdiv($number, '1000000', 1) . 'M', - strlen($number) >= 4 => bcdiv($number, '1000', 1) . 'K', - default => $number, - }; - - // Remove .0 from numbers like 1.0 as it's not needed for counts - $formattedNum = str_replace('.0', '', $formattedNum); - - return $formattedNum; + $formatter = new \NumberFormatter( + 'en_US', + \NumberFormatter::PADDING_POSITION, + ); + + return $formatter->format($number); } return $number; From c4c4da26c32e117d150fc711afee648d24f7f095 Mon Sep 17 00:00:00 2001 From: Hassan Zahirnia Date: Sat, 27 May 2023 23:47:58 +0330 Subject: [PATCH 2/3] Replace `bcmath` requirement with `intl` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d55f898..f729d8f 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": "^8.1", "filament/filament": "^2.0", "spatie/laravel-package-tools": "^1.13.5", - "ext-bcmath": "*" + "ext-intl": "*" }, "require-dev": { "laravel/pint": "^1.0", From 5489c1c60e266adf01e9864e4b17b456f452fe86 Mon Sep 17 00:00:00 2001 From: Hassan Zahirnia Date: Mon, 29 May 2023 16:17:46 +0330 Subject: [PATCH 3/3] Use current locale for NumberFormatter --- src/Overlook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Overlook.php b/src/Overlook.php index 4805d87..14a38f0 100644 --- a/src/Overlook.php +++ b/src/Overlook.php @@ -71,7 +71,7 @@ public function convertCount(string $number): string { if (config('overlook.should_convert_count')) { $formatter = new \NumberFormatter( - 'en_US', + app()->getLocale(), \NumberFormatter::PADDING_POSITION, );