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

MoneyFormatter::formatShort() returns IntlException Constructor failed when using negative decimals for significant figures. #79

Open
raven-pierce opened this issue Dec 19, 2024 · 1 comment

Comments

@raven-pierce
Copy link

Description

In this use case, I'm formatting a sum of money to three (3) significant figures using MoneyFormatter::formatShort(decimals: -3). However, if that sum is 0, the formatter fails with a simple IntlException: Constructor failed.

Adding a simple check, such as $sum > 0 ? -3 : 2 fixes the problem, but is unsightly and clunky. I think a built-in implementation could be worth it.

Steps to Reproduce

PHP v8.3
Laravel v11.35.1
Filament v3.2.130
Package dev-main, but it also occurs on v1.4.3

No changes were made to the configuration files.

The reason I'm on dev-main is because MoneyFormatter::formatShort() on v1.4.3 doesn't work as intended since the decimals argument wasn't getting pass through properly, but that got fixed in 475aa78.

Relevant Code

$sum = MoneyFormatter::formatShort($sum,
    new Currency(config('filament-money-field.default_currency')),
    config('filament-money-field.default_locale'), decimals: -3);

Expected Behavior

I'm not sure of the exact return value, but in the case of -3 precision, I think it should return 0.00 if the value is 0.

@pelmered
Copy link
Owner

Thanks for reporting.
I will look into this. I will take some time to address all open issues during next week and hopefully get close to a version 2.0 release.

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

No branches or pull requests

2 participants