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

[11.x] Add currency-aware isFractionUnit param to Number::currency() #54474

Open
wants to merge 5 commits into
base: 11.x
Choose a base branch
from

Conversation

shaedrich
Copy link
Contributor

See discussions in #54360, #54163, and #54456

Instead of

$amount = 10252; // from database, request, etc.
echo Number::currency(10252 / 1000, 'LYD', 3); // $1.025
echo Number::currency(10252 / 100, 'USD', 2); // $10.25

you can now do

$amount = 10252; // from database, request, etc.
echo Number::currency(10252, 'LYD', isFractionUnit: true); // $1.025
echo Number::currency(10252, 'USD', isFractionUnit: true); // $10.25

and don't need to know, how many Libyan dirham is one dinar (did you even know that? Me neither)

@shaedrich shaedrich marked this pull request as draft February 5, 2025 13:11
Copy link

github-actions bot commented Feb 5, 2025

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@shaedrich
Copy link
Contributor Author

There was 1 failure:

  1. Illuminate\Tests\Support\SupportNumberTest::testToCurrency
    Failed asserting that two strings are identical.
    --- Expected
    +++ Actual
    @@ @@
    -'LYD 10.252'
    +'LYD 10.252'

I must be blind 🤨

@shaedrich shaedrich changed the title Add currency-aware isFractionUnit param to Number::currency() [11.x] Add currency-aware isFractionUnit param to Number::currency() Feb 5, 2025
@PerryvanderMeer
Copy link
Contributor

PerryvanderMeer commented Feb 5, 2025

@shaedrich You might encounter some non-breaking whitespaces instead of regular spaces.

@shaedrich
Copy link
Contributor Author

Yeah, that was my assumption as well. I pasted it into VSCode with the respective setting turned on—still identical. I replaced Expected value with Actual value in the test file—git didn't register a change in the file 🤔 🤨 🕵🏻

@shaedrich
Copy link
Contributor Author

But that fixed it—thanks @PerryvanderMeer 👍🏻

@shaedrich shaedrich marked this pull request as ready for review February 5, 2025 18:00
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

Successfully merging this pull request may close these issues.

2 participants