On 8/3/23 13:55, Hans Krentel via internals wrote:
This is a proposal to consider to discuss/change the default value of

     NumberFormatter::ROUNDING_MODE

from current

     NumberFormatter::ROUND_HALFEVEN

to

     NumberFormatter::ROUND_HALFUP

.

I got the attention of this from an unrelated user in an online forum
(SO) and also checked with MDN which has it as default as well. [1]

If I'm not mistaken, ROUND_HALFUP is the rounding with number_format()
and the default rounding mode with round().

Feedback from actual ICU caretakers would be good though, because me
is entirely from a users perspective, also I know how to change
attributes to non default values, this is not a programming question
I have.

I hope you don't mind the attention to detail.

Best

-- hakre

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingmode


The default rounding mode in ICU for the number formatter appears to be "half even," and that's probably why it's the default in PHP.

See:

- https://unicode-org.github.io/icu/userguide/format_parse/numbers/rounding-modes#half-even

- https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1number_1_1NumberFormatterSettings.html#aceb7d34843e0d44e138fb3f43c98db32

The MDN documentation you linked to describes the JavaScript implementation of ECMA-402, which differs from ICU in a number of ways. One of which is in the default rounding mode for `Intl.NumberFormat`, which is not the same as ICU's `NumberFormatter` (even though most ECMA-402 implementations use icu4c internally).

Here's where ECMA-402 defines `halfExpand` as the default for `roundingMode` (see step 10 under section 15.1.3):

https://tc39.es/ecma402/#sec-setnfdigitoptions

Since PHP's intl extension follows icu4c and not ECMA-402, I think it makes sense for it to continue to use the same default values as icu4c.

Cheers,
Ben

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to