Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/NumberCurrencyTest.php
  • Loading branch information
allanmcarvalho committed Nov 20, 2023
2 parents 902cfec + 3442449 commit a11cd41
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ public static function from(Numerable|int|float|string|null $number): ?Numerable
public static function getIntlFormatter(
?string $locale,
int $style,
?int $places = null,
?int $precision = null,
?string $pattern = null,
int $places = null,
int $precision = null,
string $pattern = null,
): NumberFormatter {
$key = "$locale::$style::$places::$precision::$pattern";
if (empty(self::$formatters)) {
self::$formatters = new Collection();
}

return self::$formatters->getOrPut($key, function () use ($locale, $style, $places, $precision, $pattern) {
$formatter = new NumberFormatter($locale ?? config('app.locale', 'en'), $style);
if ($places !== null) {
Expand All @@ -78,6 +79,7 @@ public static function getIntlFormatter(
if ($pattern !== null) {
$formatter->setPattern($pattern);
}

return $formatter;
});
}
Expand Down Expand Up @@ -140,6 +142,7 @@ public static function toCurrency(
$numberFormatter->setPattern($pattern);
}
$currency = $currency ?? config('numerable.default_currency', 'USD');

return $numberFormatter->formatCurrency($value, $currency);
}

Expand Down

0 comments on commit a11cd41

Please sign in to comment.