diff --git a/src/MoneyFormatter.php b/src/MoneyFormatter.php index cf2c0e0..7a13a12 100644 --- a/src/MoneyFormatter.php +++ b/src/MoneyFormatter.php @@ -84,10 +84,12 @@ private static function getNumberFormatter(string $locale, int $style): NumberFo if ($config['intl_currency_symbol']) { $intlCurrencySymbol = $numberFormatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL); if ($numberFormatter->getTextAttribute(NumberFormatter::POSITIVE_PREFIX) !== '') { - $numberFormatter->setTextAttribute(NumberFormatter::POSITIVE_PREFIX, $intlCurrencySymbol.' '); + // "\xc2\xa0" is a non-breaking space + $numberFormatter->setTextAttribute(NumberFormatter::POSITIVE_PREFIX, $intlCurrencySymbol."\xc2\xa0"); } if ($numberFormatter->getTextAttribute(NumberFormatter::POSITIVE_SUFFIX) !== '') { - $numberFormatter->setTextAttribute(NumberFormatter::POSITIVE_SUFFIX, ' '.$intlCurrencySymbol); + // "\xc2\xa0" is a non-breaking space + $numberFormatter->setTextAttribute(NumberFormatter::POSITIVE_SUFFIX, "\xc2\xa0".$intlCurrencySymbol); } } diff --git a/tests/MoneyFormatterTest.php b/tests/MoneyFormatterTest.php index 31a4ec9..d1bd43c 100644 --- a/tests/MoneyFormatterTest.php +++ b/tests/MoneyFormatterTest.php @@ -237,4 +237,14 @@ public function testInternationalCurrencySymbol() MoneyFormatter::format(100000, new Currency('USD'), 'en_US') ); } + + public function testInternationalCurrencySymbolSuffix() + { + config(['filament-money-field.intl_currency_symbol' => true]); + + self::assertSame( + self::replaceNonBreakingSpaces('1 000,00 SEK'), + MoneyFormatter::format(100000, new Currency('EUR'), 'sv_SE') + ); + } }