use money_format:
setlocale(LC_MONETARY, 'en_US');
echo money_format('%.0i', $number);
The .0
in '%.0i'
is the right side precision.
You might need to add a filter to your twig extension. Let me know if you need help with that.
Edit:
Looking into intl extension, it seems to call formatCurrency
method from NumberFormatter
class, which in turn calls a private roundCurrency
, which eventually does:
private function roundCurrency($value, $currency)
{
$fractionDigits = Intl::getCurrencyBundle()->getFractionDigits($currency);
// ...
// Round with the formatter rounding mode
$value = $this->round($value, $fractionDigits);
// ...
}
But trying to trace where $fractionDigits
value comes from will go another 2 classes up the hierarchy, and become something as mystic as this:
public function getFractionDigits($currency)
{
try {
return $this->reader->readEntry($this->path, 'meta', array('Meta', $currency, static::INDEX_FRACTION_DIGITS));
} catch (MissingResourceException $e) {
return $this->reader->readEntry($this->path, 'meta', array('Meta', 'DEFAULT', static::INDEX_FRACTION_DIGITS));
}
}
So it might be possible to get your current extension to do the rounding, but I would probably go with my own filter as it seems to be easier and i can specify precision on the fly.