-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix number comparison in number_to_amount() in number_helper.php #7648
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
Conversation
1000 gives 1 thousand and not 1000 1000000 gives 1 million and not 1000 thousand and so on... And it compares now the same way like the function number_to_size above
|
This seems reasonable. Can you add test code and changelog? |
Yes, I will do this in the next days. What do you think about the command line 81 This command is dangerous in my opinion. And all other chars like apostroph or whitespace used as thousends separator are not stripped anyway. |
|
The function has the parameter |
|
to make behaviour dependent on language makes it too complex for this simple function. |
|
We have a plan to release next bug fix (and 4.4.0) soon. |
|
While writing the tests I came across further counterintuitive behaviour. Output: In my opinion, the correct output for the number 999500 would be 1 million and not 1,000 thousand. |
|
If you want to fix it, something like this (to all cases)? --- a/system/Helpers/number_helper.php
+++ b/system/Helpers/number_helper.php
@@ -106,6 +106,11 @@ if (! function_exists('number_to_amount')) {
} elseif ($num >= 1000) {
$suffix = lang('Number.thousand', [], $generalLocale);
$num = round(($num / 1000), $precision);
+
+ if ($num >= 1000) {
+ $num = 1;
+ $suffix = lang('Number.million', [], $generalLocale);
+ }
}
return format_number($num, $precision, $locale, ['after' => $suffix]); |
Added more tests for number_to_amount()
add infos for changes in ``number_to_amount``
Adopt suggested change from kenjis Co-authored-by: kenjis <[email protected]>
add phpDoc params to number_to_amount function
Code style
|
@sba Thank you for update! This PR contains a merge commit that is not needed. |
|
@kenjis sorry, I tried, but I don't get it with git rebase... i do it a bit primitive in the online editor on github.com to have verified commits. I will do a new PR with the changes. |
|
@sba Thank you for trying. I hope you learn to use If you need help, feel free to ask. |
Description
1000 gives 1 thousand and not 1000
1000000 gives 1 million and not 1000 thousand
and so on...
And it compares now the same way like the function number_to_size above
Checklist: