Re: Re: ICU - NumberFormatter::ROUNDING_MODE default ROUND_HALFEVEN
| From: | Hans Krentel via internals | Date: | Thu, 03 Aug 2023 20:15:25 +0000 |
| Subject: | Re: Re: ICU - NumberFormatter::ROUNDING_MODE default ROUND_HALFEVEN | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120885@lists.php.net to get a copy of this message | ||
On Thursday 03 August 2023 21:07:57 (+02:00), Ben Ramsey wrote:
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 forThank you for this differentiation, my reference to MDN I found interesting as they've chosen the same approach as PHP with number_format(), obviously they also choose the name of the function because of that^^. Jokes aside, your reference to ICU itself and PHPs connection to it is most likely the true explanation why that is the default rounding mode in NumberFormatter. And honestly, from a core perspective, it would likely be surprising if it would be otherwise then (the change asked about). I'm not the person to draw this line, but in hindsight of output formatting - obviously the totally other side - the current default is surprising, too. But it is certainly the safer path to not change it. For now, I've already learned a lot more and should take some time to look into this. E.g. understanding why this is the default in ICU, perhaps there is some more valuable information. Thanks & Best, -- hakreIntl.NumberFormat, which is not the same as ICU'sNumberFormatter(even though most ECMA-402 implementations use icu4c internally). Here's where ECMA-402 defineshalfExpandas the default forroundingMode(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.