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

[10.x] Add Number class; convert given number to percentage. #48909

Closed
wants to merge 2 commits into from

Conversation

andrius-386
Copy link

About

This is follow up for initiative to add Number utility as part of core Laravel framework. More on that in the conversation started in #48827 (comment) and #48845.

What I'm trying to achieve

Adding proof of concept for formatting percentage value using different locales. Currently supporting 3 locales (en, fr, de) but others can be added later once path forward is clear.

Main question to answer: should number formatting depend on php-intl extension (and NumberFormatter) or have locale implementation 'in-house' as shown in the draft PR?

Both implementations have pros and cons.

  • php-intl extension: adding another dependency; handling cases where extension is not enabled; most likely using small fraction extension capabilities. However it adds wide variety of locale support out of the box.
  • in-house implementation: lower number for supported locales. However, no extra dependencies; more control and flexibility.

All ideas and feedback are welcome, thanks!

@caendesilva
Copy link
Contributor

Hmm, interesting approach! I like the customization options. Let's see what others think!

I think what I did by adding the extension as a suggestion is a fair compromise as it adds less code to maintain. Simple methods like the bytesToHuman don't need the extension either.

@dennisprudlo
Copy link
Contributor

That would definitely helpful. For applications in different languages with different grammatical rules for units, the Number helper would return wrong results. So displaying a file size in german would require to create a new custom number helper that does almost exactly the same thing.

@driesvints driesvints changed the title Add Number class; convert given number to percentage. [10.x] Add Number class; convert given number to percentage. Nov 6, 2023
@localusercamp
Copy link
Contributor

localusercamp commented Nov 7, 2023

It will be nice to have some sort of Math class in Laravel. It could contain a bunch of really helpful utilities for projects (geometric mean, percent calculation with safe zero division, and so on).
As far as I can see what you are trying to achieve is formatting the number. So in my opinion there must be several functions related to format and percentage must calculate the percentage of two numbers.
It also will be nice to have a "fluent" implementation of the Number class (like Stringable).

@foremtehan
Copy link
Contributor

#48845

@driesvints
Copy link
Member

We merged a different proposal. Thanks for your PR!

@driesvints driesvints closed this Nov 16, 2023
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.

6 participants