base_currency = $base_currency; $this->locale = Locale::getDefault(); } /** * @param string $value The value that should be * @param Currency|null $currency * @param int $decimals * @return string */ public function format(string $value, ?Currency $currency = null, $decimals = 5) { $iso_code = $this->base_currency; if ($currency !== null && !empty($currency->getIsoCode())) { $iso_code = $currency->getIsoCode(); } $number_formatter = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY); $number_formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $decimals); return $number_formatter->formatCurrency((float) $value, $iso_code); } }