Skip to content

Commit daf8ca8

Browse files
committed
applied config to formatter
1 parent a4a3a20 commit daf8ca8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Money.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ public function formatForHumans(?string $locale = null, ?Closure $callback = nul
593593

594594
$formatter = new \NumberFormatter($locale ?: static::getLocale(), \NumberFormatter::PADDING_POSITION);
595595

596+
$formatter->setSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $this->currency->getDecimalMark());
597+
$formatter->setSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $this->currency->getThousandsSeparator());
598+
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $this->currency->getPrecision());
599+
596600
if (is_callable($callback)) {
597601
$callback($formatter);
598602
}
@@ -615,6 +619,10 @@ public function formatLocale(?string $locale = null, ?Closure $callback = null):
615619

616620
$formatter = new \NumberFormatter($locale ?: static::getLocale(), \NumberFormatter::CURRENCY);
617621

622+
$formatter->setSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $this->currency->getDecimalMark());
623+
$formatter->setSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $this->currency->getThousandsSeparator());
624+
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $this->currency->getPrecision());
625+
618626
if (is_callable($callback)) {
619627
$callback($formatter);
620628
}

tests/MoneyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ public function testFormatForHumans($expected, $cur, $amount, $locale, $message)
368368
public function providesFormatForHumans()
369369
{
370370
return [
371-
['€1,5K', 'EUR', 154848.25895, 'nl_NL', 'Example: ' . __LINE__],
372-
['$1.5K', 'USD', 154848.25895, 'en_US', 'Example: ' . __LINE__],
371+
['€1,55K', 'EUR', 154848.25895, 'nl_NL', 'Example: ' . __LINE__],
372+
['$1.55K', 'USD', 154848.25895, 'en_US', 'Example: ' . __LINE__],
373373
];
374374
}
375375

0 commit comments

Comments
 (0)