php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63140 Currency Formatter ignores fraction digits
Submitted: 2012-09-22 16:39 UTC Modified: 2012-10-05 17:31 UTC
From: mic dot gallego at gmail dot com Assigned: cataphract (profile)
Status: Not a bug Package: intl (PECL)
PHP Version: 5.4.7 OS: OS X 10.8
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mic dot gallego at gmail dot com
New email:
PHP Version: OS:

 

 [2012-09-22 16:39 UTC] mic dot gallego at gmail dot com
Description:
------------
Hi,

The formatCurrency of NumberFormatter does not correctly take into account the 
fraction digits (while PHP money_format function works as expected).

Test script:
---------------
$usFormatter = new NumberFormatter('en-US', NumberFormatter::CURRENCY);
$usFormatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
	
echo $usFormatter->formatCurrency('45', 'USD') . PHP_EOL;
echo $usFormatter->formatCurrency('45', 'EUR') . PHP_EOL;
	
$frFormatter = new NumberFormatter('fr-FR', NumberFormatter::CURRENCY);
$frFormatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);

echo $frFormatter->formatCurrency('45', 'EUR') . PHP_EOL;
echo $frFormatter->formatCurrency('45', 'USD') . PHP_EOL;

Expected result:
----------------
$45
€45
45 €
45 $US

Actual result:
--------------
$45
€45.00
45 €
45,00 $US

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-23 13:45 UTC] laruence@php.net
-Assigned To: +Assigned To: cataphract
 [2012-10-04 13:18 UTC] jpauli@php.net
AFAIK, this is an ICU bug as PHP proxies to ICU's function for such a feature.

May be something like http://bugs.icu-project.org/trac/ticket/7667 in ICU-4.4.1
 [2012-10-05 08:21 UTC] jpauli@php.net
I confirm this is an ICU bug in 4.4.x branch.
Consider upgrading libicu, 4.8.x gives correct result
 [2012-10-05 17:31 UTC] cataphract@php.net
Not a PHP bug. Thanks.
 [2012-10-05 17:31 UTC] cataphract@php.net
-Status: Assigned +Status: Not a bug
 [2015-12-21 17:10 UTC] attila at szeremi dot org
I'm still getting this issue with ICU in PHP 5.5 with this ICU version:

Internationalization support => enabled
 version => 1.1.0
 ICU version => 4.8.1.1
 ICU Data version => 4.8.1
 [2017-09-04 14:33 UTC] mathieu at rochette dot cc
I still have the same issue with libicu 52.1 and both php 5.6.31 & 7.1.9:

$45
€45.00
45 €
45,00 $US
 [2018-02-05 16:19 UTC] zoltan dot s at webintegreat dot com
It still doesnt work with PHP7.0 and libicu57.1-8

$value = 1234567899.987654321;

$formatter = new \NumberFormatter('de_DE', \NumberFormatter::CURRENCY);
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, 0);
$result = $formatter->formatCurrency($value, 'EUR');
echo "value de_DE (EUR): $result<br/>\n";

$formatter = new \NumberFormatter('de_DE', \NumberFormatter::CURRENCY);
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, 0);
$result = $formatter->formatCurrency($value, 'USD');
echo "value de_DE (USD): $result<br/>\n";

$formatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, 0);
$result = $formatter->formatCurrency($value, 'USD');
echo "value en_US (USD): $result<br/>\n";


$formatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, 0);
$result = $formatter->formatCurrency($value, 'EUR');
echo "value en_US (EUR): $result<br/>\n";


Expected result:
----------------

value de_DE (EUR): 1.234.567.900 €
value de_DE (USD): 1.234.567.900 $
value en_US (USD): $1,234,567,900
value en_US (EUR): €1,234,567,900


Actual result:
--------------

value de_DE (EUR): 1.234.567.900 €
value de_DE (USD): 1.234.567.899,99 $
value en_US (USD): $1,234,567,900
value en_US (EUR): €1,234,567,899.99
 [2020-01-31 14:48 UTC] jorrit at ncode dot nl
Seems to work in 7.4.2.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 14:01:30 2024 UTC