Req #76093 [Com]: numfmt_format should accept string numbers rather than casting to float

From: Date: Wed, 15 Dec 2021 19:47:54 +0000
Subject: Req #76093 [Com]: numfmt_format should accept string numbers rather than casting to float
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238444@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76093&edit=1

 ID:                 76093
 Comment by:         cananian at wikimedia dot org
 Reported by:        Wes dot nospam at example dot org
 Summary:            numfmt_format  should accept string numbers rather
                     than casting to float
 Status:             Open
 Type:               Feature/Change Request
 Package:            I18N and L10N related
 PHP Version:        7.2.3
 Block user comment: N
 Private report:     N

 New Comment:

github pr is now at https://github.com/php/php-src/pull/7782

Sorry for the long delay!  It got lost in my tree for a while.

I have a followup for formatCurrency at https://github.com/cscott/php-src/tree/bug76093-followup
-- as currently written it required a new method in ICU, but as documented in https://unicode-org.atlassian.net/browse/ICU-21479
this can actually be done with the current ICU API in a certain way; I need to update the follow up
to do things That Way.


Previous Comments:
------------------------------------------------------------------------
[2021-09-16 13:02:39] cmb@php.net

> I have a patch written, I'll post it shortly.

Any update?  Also, better submit a pull request[1] instead of
attaching a patch for better visibility.

[1] <https://github.com/php/php-src/pulls>

------------------------------------------------------------------------
[2021-01-28 20:39:09] cananian at wikimedia dot org

This is the root cause of Wikimedia bug T268456, fwiw: https://phabricator.wikimedia.org/T268456

I have a patch written, I'll post it shortly.

There's a similar issue with currency formatting, but that requires an upstream patch to
libicu: https://unicode-org.atlassian.net/browse/ICU-21479

------------------------------------------------------------------------
[2021-01-28 14:35:34] mail at lucaswerkmeister dot de

Hm, I don’t see so many differences between General Decimal Arithmetic numeric strings [1] and
PHP numeric strings [2]:

1. PHP allows leading and trailing whitespace, GDA does not.
2. GDA includes special values (s)NaN and Inf(inity), PHP does not.

The syntax for finite numbers themselves is identical, as far as I can tell. (For instance, both
allow lower- and uppercase E in exponential notation, empty digits before xor after decimal
separator, only ASCII digits 0-9, leading zeroes anywhere…) Maybe this was different before PHP
8’s improved numeric strings [3].

[1]: http://speleotrove.com/decimal/daconvs.html#refnumsyn
[2]: https://www.php.net/manual/en/language.types.numeric-strings.php
[3]: https://wiki.php.net/rfc/saner-numeric-strings

------------------------------------------------------------------------
[2021-01-22 21:02:20] cananian at wikimedia dot org

libicu has the code to create the Decimal Number for you.

You'd use https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1Formattable.html#a0505d26515fa1bbac3dd46a7e15e120e
to create a Formattable from the string input, and then call formatUFormattable() on that: https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/unum_8h.html#aec903c32ade7d632fb7125a5dfd667ea

Should be pretty straight-forward.

------------------------------------------------------------------------
[2020-03-05 10:05:46] cmb@php.net

ICU has unum_formatDecimal()[1]:

| The syntax of the input number is a "numeric string" as defined
| in the Decimal Arithmetic Specification, available at
| http://speleotrove.com/decimal

From a quick glimpse, this looks quite different to PHP's numeric
strings, so supporting it wouldn't be straight forward.

[1] <https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/unum_8h.html#a59870a322f012dc1b9d99cf8a7b708f1>

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=76093


--
Edit this bug report at https://bugs.php.net/bug.php?id=76093&edit=1


Thread (1 message)

  • cananian at wikimedia dot org
  • Unknown Message
    • cananian at wikimedia dot org
« previous php.bugs (#238444) next »