Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberFormatter currency output format changed (ICU issue?) #17218

Closed
xHeaven opened this issue Dec 19, 2024 · 4 comments
Closed

NumberFormatter currency output format changed (ICU issue?) #17218

xHeaven opened this issue Dec 19, 2024 · 4 comments

Comments

@xHeaven
Copy link

xHeaven commented Dec 19, 2024

Description

The following code:

<?php
$fmt = new NumberFormatter( 'en_US', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "HUF")."\n";

$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "HUF")."\n";

$fmt = new NumberFormatter( 'hu_HU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "HUF")."\n";

Resulted in this output:

€1,234,567.89
HUF 1,234,567.89
€ 1,234,567.89
HUF 1,234,567.89
€ 1,234,567.89
HUF 1,234,567.89

But I expected this output instead:

€1,234,567.89
HUF 1,234,567.89
1.234.567,89 €
1.234.567,89 HUF
1 234 567,89 EUR
1 234 567,89 Ft

Is this something with the ICU project? I've tested with 2 different systems, one being Alpine Linux v3.21 x86_64 with PHP 8.4.1 and another being Ubuntu 22.04 LTS with PHP 8.3.11.

On the Alpine system, my icu-libs version is 74.2, on the Ubuntu system my libicu version is 70.1.

Edit: I've tried to compile the same (70.1) version of ICU from source on my Alpine system, but either I'm doing something wrong, or it doesn't matter which version I'm using on my system - which would make no sense, because it works perfectly on 3v4l on PHP 8.4.1.

This is my php -i | grep ICU output though, PHP doesn't give a flying one what's on my system. Any advice?

ICU version => 74.2
ICU Data version => 74.2
ICU TZData version => 2023c
ICU Unicode version => 15.1

PHP Version

PHP 8.4.1

Operating System

Alpine Linux v3.21 x86_64

@devnexen
Copy link
Member

Do not know for sure, but that might be a ICU data installed difference between minimalist distro such as Alpine vs something like Ubuntu. But I ll try to have a look later unless someone knows already.

@xHeaven
Copy link
Author

xHeaven commented Dec 19, 2024

Do not know for sure, but that might be a ICU data installed difference between minimalist distro such as Alpine vs something like Ubuntu. But I ll try to have a look later unless someone knows already.

Thanks a lot for the swift response, I'll try looking in the meantime as well and update the issue if I find anything useful.
Hopefully someone already knows what's up, because the current formatted currency output is just completely wrong - especially in a finance-related system, where this actually matters quite a lot.

@devnexen
Copy link
Member

So as expected, the pb lies in a missing alpine package, icu-data-full; before installation I get the same output however it solves after.

@xHeaven
Copy link
Author

xHeaven commented Dec 20, 2024

So as expected, the pb lies in a missing alpine package, icu-data-full; before installation I get the same output however it solves after.

It indeed does solve the problem! Thanks a lot, I would've never figured it out. I've just installed icu-data-full and now the code behaves as expected.

Appreciate your help, perhaps you can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants