laravel/framework · error · InvalidArgumentException
Array value for key [%s] must be a float, %s found.
Error message
Array value for key [%s] must be a float, %s found.
What it means
Thrown by Arr::float() when the value resolved via Arr::get() fails is_float(). Note this accessor does NOT coerce numeric strings (unlike the cache equivalent), so the string '3.14' or an int 3 will fail.
Source
Thrown at src/Illuminate/Collections/Arr.php:401
$result[] = $value;
}
}
}
return $result;
}
/**
* Get a float item from an array using "dot" notation.
*
* @throws \InvalidArgumentException
*/
public static function float(ArrayAccess|array $array, string|int|null $key, ?float $default = null): float
{
$value = Arr::get($array, $key, $default);
if (! is_float($value)) {
throw new InvalidArgumentException(
sprintf('Array value for key [%s] must be a float, %s found.', $key, gettype($value))
);
}
return $value;
}
/**
* Remove one or many array items from a given array using "dot" notation.
*
* @param array $array
* @param array|string|int|float $keys
* @return void
*/
public static function forget(&$array, $keys)
{
$original = &$array;
View on GitHub (pinned to bd6b5437e6)
Solutions
- Pass a float default: Arr::float($data, 'price', 0.0).
- Cast the source value to float before it lands in the array.
- Use Arr::get() + (float) cast if you want numeric-string coercion.
- Fix the dot path so it points at a real float node.
Example fix
// before $price = Arr::float($order, 'totals.grand'); // after $price = Arr::float($order, 'totals.grand', 0.0); // or coerce $price = (float) Arr::get($order, 'totals.grand', 0);
Defensive patterns
Strategy: type-guard
Validate before calling
$value = Arr::get($data, 'price');
if (! is_float($value)) {
$value = (float) $value;
} Type guard
function arrayKeyIsFloat(array $array, string $key): bool {
return is_float(Arr::get($array, $key));
} Try / catch
try {
$price = Arr::float($order, 'totals.grand', 0.0);
} catch (\InvalidArgumentException $e) {
$price = (float) Arr::get($order, 'totals.grand', 0);
} Prevention
- Arr::float() does not coerce — cast numeric strings to float before reading.
- Pass a float default to Arr::float().
- Decode JSON with appropriate flags so numbers stay numeric.
When it happens
Trigger: Calling Arr::float($data, 'price') when the value is an int, a numeric string like '3.14', an array, or null (missing key, no float default).
Common situations: JSON decoded payload where prices come through as strings; reading a value stored as int cents; a config key that is sometimes null.
Related errors
- Array value for key [%s] must be an array, %s found.
- Array value for key [%s] must be a boolean, %s found.
- Items cannot be represented by a scalar value.
- Array value for key [%s] must be an integer, %s found.
- Array value for key [%s] must be a string, %s found.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/657df64d9acab55b.json.
Report an issue: GitHub.