Skip to content

Commit

Permalink
Merge pull request #15 from HassanZahirnia/patch-1
Browse files Browse the repository at this point in the history
Replace bcdiv with NumberFormatter in convertCount method
  • Loading branch information
awcodes authored May 29, 2023
2 parents 96786eb + 5489c1c commit 09cb616
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 6 additions & 12 deletions src/Overlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
app()->getLocale(),
\NumberFormatter::PADDING_POSITION,
);

return $formatter->format($number);
}

return $number;
Expand Down

0 comments on commit 09cb616

Please sign in to comment.