Re: ICU - NumberFormatter::ROUNDING_MODE default ROUND_HALFEVEN
| From: | Ben Ramsey | Date: | Thu, 03 Aug 2023 19:07:57 +0000 |
| Subject: | Re: ICU - NumberFormatter::ROUNDING_MODE default ROUND_HALFEVEN | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120882@lists.php.net to get a copy of this message | ||
On 8/3/23 13:55, Hans Krentel via internals wrote:
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
This is a proposal to consider to discuss/change the default value ofThe 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 forNumberFormatter::ROUNDING_MODEfrom currentNumberFormatter::ROUND_HALFEVENtoNumberFormatter::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
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: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc