You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Number::format() method has unexpected behavior where the $precision parameter is completely ignored if $maxPrecision is provided. This is counterintuitive because:
$precision comes before $maxPrecision in the parameter list
A later parameter should not completely override an earlier one
I would expect both parameters to work together (min and max precision)
useIlluminate\Support\Number;
// This returns "5,1" instead of "5,10"
Number::format(5.1, precision: 2, maxPrecision: 2, locale: 'de');
The $precision parameter is completely ignored because $maxPrecision is set.
Expected Behavior
When both $precision and $maxPrecision are provided:
$precision should set the minimum fraction digits
$maxPrecision should set the maximum fraction digits
This would allow proper formatting like "5,10" while still capping at the maximum.
Proposed Solution
if (! is_null($precision)) {
$formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $precision);
}
if (! is_null($maxPrecision)) {
$formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $maxPrecision);
} elseif (! is_null($precision)) {
// If only precision is set, use it for both min and max (current behavior)$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $precision);
}
This would:
Always respect $precision as minimum fraction digits when provided
Maintain backward compatibility when only $precision or only $maxPrecision is set
Allow both parameters to work together logically
Steps To Reproduce
useIlluminate\Support\Number;
// Test case 1: Only precisionecho Number::format(5.1, precision: 2, locale: 'de');
// Current: "5,10" ✓// Expected: "5,10" ✓// Test case 2: Both precision and maxPrecisionecho Number::format(5.1, precision: 2, maxPrecision: 4, locale: 'de');
// Current: "5,1" ❌ (precision ignored)// Expected: "5,10" ✓ (min 2, max 4 decimals)// Test case 3: Value with more decimals than maxecho Number::format(5.12345, precision: 2, maxPrecision: 3, locale: 'de');
// Expected: "5,123" ✓ (respects max)
This discussion was converted from issue #58517 on January 28, 2026 07:02.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
12.48.1
PHP Version
8.4
Description
The
Number::format()method has unexpected behavior where the$precisionparameter is completely ignored if$maxPrecisionis provided. This is counterintuitive because:Current Behavior
8ab2184#diff-2866de1046fe4e657a94ff101ff6b049818966c89117bc87a9d2017c63315214R35-R40
The
$precisionparameter is completely ignored because$maxPrecisionis set.Expected Behavior
When both
$precisionand$maxPrecisionare provided:This would allow proper formatting like "5,10" while still capping at the maximum.
Proposed Solution
This would:
$precisionas minimum fraction digits when provided$precisionor only$maxPrecisionis setSteps To Reproduce
Beta Was this translation helpful? Give feedback.
All reactions