Trying to remove the last .00 from a currency formatted using PHP NumberFormatter but it doesn't seem possible. I can see this option but it doesn't seem to affect a currency: DECIMAL_ALWAYS_SHOWN
$nf = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
$nf->formatCurrency(0, 'EUR');
// Output is €0.00 but it doesn't seem possible to remove the .00
I would do a str_replace for .00 but this may be different depending on locale so it doesn't seem that easy.
You can force that only with the format()
method:
$nf = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
$nf->setTextAttribute(\NumberFormatter::CURRENCY_CODE, 'EUR');
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 0);
echo $nf->format(1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With