为什么 PHP 的 NumberFormatter 是四舍五入格式的瑞士法郎金额?

Why is PHP's NumberFormatter nickel-rounding formatted Swiss Franc amounts?

使用 formatCurrency() method on the NumberFormatter class 和 CHF(瑞士法郎)货币对我来说是四舍五入到最接近的镍数量 (0.05)。

代码:

$formatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
echo $formatter->formatCurrency('12.34', 'CHF');

结果:

CHF12.35

请注意,数值 12.34 四舍五入为 12.35。起初,我认为这可能是预料之中的,并且是一种我不熟悉的处理资金的新方式。事实证明,这不是它应该如何工作的。 (https://money.stackexchange.com/q/105014/81599)

为什么它向上/向下取整到 PHP 中最接近的镍量,我该如何解决?

答案实际上在 [=28= 之外,在 ICU library which PHP wraps via the Internationalization extension. As it turns out, I had an outdated version (50.x) of the ICU library which included the nickel-rounding bug within it. Updating to the nearest ICU library (as of today, 63.1) 之内将允许您使用最新的国际化标准,包括此错误修复。我不确定 ICU 的哪个 特定升级解决了我的问题,但我知道最新的解决了这个问题。

至于为什么会发生这种情况,瑞士逐步取消了 0.01 面额的货币,最低面额实际上是 0.05 现金。潜在地,在 ICU 上工作的开发人员会感到困惑,因为阅读 this Unicode chart 最初可能会产生误导。

相关: