php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53735 NumberFormatter returns NaN when converting float point
Submitted: 2011-01-13 14:46 UTC Modified: 2016-06-06 19:16 UTC
Votes:16
Avg. Score:4.8 ± 0.6
Reproduced:15 of 15 (100.0%)
Same Version:5 (33.3%)
Same OS:4 (26.7%)
From: mortenskyt at gmail dot com Assigned:
Status: Not a bug Package: I18N and L10N related
PHP Version: 5.3.5 OS: MacOS X 10.6.6
Private report: No CVE-ID: None
 [2011-01-13 14:46 UTC] mortenskyt at gmail dot com
Description:
------------
In PHP 5.3.5, giving float point values to numfmt_format doesn't work when 
setlocale is set to a country using comma instead of dot in floating point.

Also does not work in PHP 5.3.4 (FreeBSD)

DOES work on 5.3.3 (FreeBSD)


Perhaps interesting notes from my configuration:

intl
Internationalization support => enabled
version => 1.1.0
ICU version => 4.6

Directive => Local Value => Master Value
intl.default_locale => no value => no value
intl.error_level => 0 => 0

Test script:
---------------
<?php
$fmt = numfmt_create("da_DK", \NumberFormatter::CURRENCY);

echo numfmt_format($fmt, 5.5)."\n";
setlocale(LC_ALL, "da_DK.UTF-8");

echo numfmt_format($fmt, 5.5)."\n";
echo numfmt_format($fmt, "5,5")."\n";

Expected result:
----------------
5,50 kr
5,50 kr
5,00 kr

Actual result:
--------------
5,50 kr
NaN
5,00 kr

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-13 22:49 UTC] felipe@php.net
-Package: *Languages/Translation +Package: I18N and L10N related
 [2011-01-22 08:41 UTC] stas@php.net
-Status: Open +Status: Feedback
 [2011-01-22 08:41 UTC] stas@php.net
Works for me in 5.3 on Mac OS X. Which ICU version do you have (check phpinfo())?
 [2011-01-22 13:40 UTC] mortenskyt at gmail dot com
-Status: Feedback +Status: Open
 [2011-01-22 13:40 UTC] mortenskyt at gmail dot com
Hello again,

On my Mac with PHP 5.3.5 from Macports:

Internationalization support => enabled
version => 1.1.0
ICU version => 4.6

(same version on non-working FreeBSD PHP 5.3.4-machine)


The FreeBSD-machine with PHP 5.3.3, which works with no issues:

Internationalization support => enabled
version => 1.0.3
ICU version => 3.8.1
 [2011-01-24 01:36 UTC] stas@php.net
I works for me with ICU 4.3.4. Maybe they broke something in 4.6... 
May be related to this ticket: http://bugs.icu-project.org/trac/ticket/6711
 [2011-10-07 10:46 UTC] martin at tajur dot ee
The exact same thing happens on all Debian Squeeze installations, given that php5-
intl bundle is installed from the default debian package sources. The error 
appears right after switching locale to something other than default ("en", 
presumably) and trying to format a number with a comma using NumberFormatter. I 
was able to fix the issue on Debian Lenny by manually downgrading ICU library to 
3.8 but ICU 3.8 does not work on Squeeze which raises importance of this issue 
even more.
 [2012-05-24 09:59 UTC] arthur_jambon at prizee dot fr
Get always NaN with NumberFormatter::ORDINAL if the current local is not en_US.

PHP 5.3.3
ICU lib 4.4.1-8
OS Debian Squeeze
 [2013-03-11 10:52 UTC] bghome at gmail dot com
I can reproduce this with PHP 5.3.10 on Ubuntu 12.04 64.
It is strange for me, because running from CLI works as expected.

Code to run:
$f = new NumberFormatter('hu_HU', NumberFormatter::PERCENT, '#,##0%');
echo $f->format(0.26) . "\n";
 [2015-10-01 20:04 UTC] info at netonme dot de
PHP Version 5.5.29-1
ICU version 4.4.1

$fmt = new \NumberFormatter("de_DE", \NumberFormatter::DECIMAL);
$fmt->format(23.25);

Returns NaN
 [2016-06-06 19:16 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2016-06-06 19:16 UTC] ab@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

First reported with PHP 5.3, the last comment is about 5.5. ICU version producing the issue stays however within the same version range. Today PHP 5.5+ with ICU 51.2+ shows no issues. This brings to the conclusion, that the issue doesn't lay on PHP. Rougly same ICU (or maybe just data) version range produces the issue. For what matters, I've added ext/intl/tests/bug53735.phpt with all the snippets from this ticket.

Thanks.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 16:01:24 2019 UTC