Currently number_format()
could accept one, two or four args. If three args
is passed then you will receive "wrong parameter count for number_format()
"
error (ArgumentCountError).
It have four parameters: float $number, int $decimals, string $dec_point
and string $thousands_sep.
- If one arg is passed, then $decimals = 0 and $thousands_sep = ",".
- If two args is passed, then $dec_point = "." and $thousands_sep = ",".
- If four args is passed, then it will respect given args;
There some cases where we just don't need a $thousands_sep, so I suggest to
accept three args with $thousands_sep = '' (and not a comma).
It will works fine for the doc (
https://www.php.net/manual/en/function.number-format.php) example:
// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', ''); // Currently
$english_format_number = number_format($number, 2, '.'); // After
// 1234.57 (same result)
The fourth parameter will change "the behavior" if compared with the
another original cases, but it will happen because there is no reason to
use three args if you pretends to keep the comma as fourth arg once that
normally you will use or "." or "," as decimal separator.
- If you pretends to use dot + comma, just use two args;
- If you pretends to use comma + dot, just use four args;
- If you pretends to use dot + nothing, use three args;
- If you pretends to use comma + nothing, use three args;
--
David Rodrigues