Skip to content

[13.x] Fix mode() returning truncated values for floats - #62063

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:mode-floats
Oct 17, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:mode-floats

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

mode() uses the values as array keys to count them, so floats get truncated to ints and you get back something that isn't even in the collection. This hits anything with decimals, like ratings, prices, grades or percentages:

$reviews->mode('rating'); // [4] for ratings 4.5, 4.7, 4.7
$products->mode('price'); // [19] for prices 19.99, 19.99, 24.50

It can also mix up different values, [1.2, 1.7, 2.0] returns [1] because 1.2 and 1.7 both become 1.

Now floats are counted under a string key and the original value is returned. Nothing changes for ints and whole floats like 1.0.

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.

2 participants