php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71008 NumberFormatter::parseCurrency() works incorrectly
Submitted: 2015-12-01 12:58 UTC Modified: 2021-06-14 17:11 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: loco at andrews dot lv Assigned: cmb (profile)
Status: Not a bug Package: intl (PECL)
PHP Version: 5.6.16 OS: Linux 4.3.0-gentoo x86_64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: loco at andrews dot lv
New email:
PHP Version: OS:

 

 [2015-12-01 12:58 UTC] loco at andrews dot lv
Description:
------------
Different results are returned when running the test script and hitting browser refresh button:

--test 1--

Original number: 462.501

NumberFormatter::parseCurency() returns: 462.5 

--test 2--

Original number: 462.501

NumberFormatter::parseCurency() returns: 462

--test 3--

Original number: 462.501

NumberFormatter::parseCurency() returns: 462.5

--test 4--

Original number: 462.501

NumberFormatter::parseCurency() returns: 462

....

Internationalization support	enabled
version	                        1.1.0
ICU version	                55.1
ICU Data version	        55.1


Test script:
---------------
<?php

  // Run this script then refresh the page several times in the browser 
  // in order to get different results

  print "<pre>\n";

  $number = 462.501;
  print 'Original number: '.$number."\n\n";

  $formatter = new NumberFormatter('nl_BE', NumberFormatter::CURRENCY);
  $value = $formatter->format($number);

  print 'NumberFormatter::parseCurency() returns: '.$formatter->parseCurrency($value, $currency)."\n";

  print "</pre>\n";
?>

Expected result:
----------------
Original number: 462.501

NumberFormatter::parseCurency() returns: 462.5



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-19 21:48 UTC] flack at contentcontrol-berlin dot de
I have seen this issue, too, on two Debian 8 servers (can only reproduce on one of them any longer). I run the following script:

$formatter = new NumberFormatter('de_DE', NumberFormatter::DECIMAL);
var_dump($formatter->parse('9,90'));

Sometimes it outputs float(9.9), sometimes it outputs float(9). What could possibly cause this?
 [2021-06-14 17:11 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-06-14 17:11 UTC] cmb@php.net
Float to string conversion is locale sensitive prior to PHP 8.0.0,
and the locale is set per process.  That explains why that
sometimes worked, and sometimes failed.  See also
<https://3v4l.org/bNon1>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC