-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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 a new Number::scientific()
method to format numbers in E-notation
#54451
base: 11.x
Are you sure you want to change the base?
[11.x] Add a new Number::scientific()
method to format numbers in E-notation
#54451
Conversation
How about adding an exponent:
|
Thanks for the suggestion! I'm not sure if the logic is correct or not because the method is formatting not converting. // syntax
scientific(int|float $number, int $precision = 2, ?string $locale = null) But if this was necessary, so we could be added it later. |
How is this formatting if you randomly choose the exponent with no way to change that. The exponent is chosen either way, the only difference being that I proposed to make it customizable. Both 1.23E6 and 12.3E5 represent the same number. When you choose to randomly select an exponent, then you could take the exponent that doesn't cut off numbers with the given precision as 1.23E6 converts back to 1230000, not 1234567. |
Thanks for the clarification, I understood your point exactly and it is indeed correct. |
Next thing to keep in mind is that "scientific notation" can stand for different notations:
I came up with the same feature a while ago and didn't have the time to finish it yet. Might be helpful to you: |
@shaedrich I improved code and raised again. last commit 885a879 4ba5350 |
@waadmawlood Your variable wording is definitely better than mine—one never stops learning 😅👍🏻 |
Number::scientific()
method to format numbers in E-notation.
Number::scientific()
method to format numbers in E-notation.Number::scientific()
method to format numbers in E-notation
Add scientific notation formatting to the Number class
This PR adds a new
scientific()
method to theNumber
class that formats numbers in scientific notation using PHP's Intl extension.The new method allows formatting numbers in E-notation with configurable precision and locale support. For example:
Key features:
This addition complements the existing number formatting capabilities in Laravel's Number class by providing scientific notation support for working with very large or small numbers in a standardized way.