{"id":"657df64d9acab55b","repo":"laravel/framework","slug":"array-value-for-key-s-must-be-a-float-s-found","errorCode":null,"errorMessage":"Array value for key [%s] must be a float, %s found.","messagePattern":"Array value for key \\[(.+?)\\] must be a float, (.+?) found\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/Arr.php","lineNumber":401,"sourceCode":"                    $result[] = $value;\n                }\n            }\n        }\n\n        return $result;\n    }\n\n    /**\n     * Get a float item from an array using \"dot\" notation.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function float(ArrayAccess|array $array, string|int|null $key, ?float $default = null): float\n    {\n        $value = Arr::get($array, $key, $default);\n\n        if (! is_float($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Array value for key [%s] must be a float, %s found.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Remove one or many array items from a given array using \"dot\" notation.\n     *\n     * @param  array  $array\n     * @param  array|string|int|float  $keys\n     * @return void\n     */\n    public static function forget(&$array, $keys)\n    {\n        $original = &$array;\n","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Collections/Arr.php#L383-L419","documentation":"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.","triggerScenarios":"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).","commonSituations":"JSON decoded payload where prices come through as strings; reading a value stored as int cents; a config key that is sometimes null.","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."],"exampleFix":"// before\n$price = Arr::float($order, 'totals.grand');\n\n// after\n$price = Arr::float($order, 'totals.grand', 0.0);\n// or coerce\n$price = (float) Arr::get($order, 'totals.grand', 0);","handlingStrategy":"type-guard","validationCode":"$value = Arr::get($data, 'price');\nif (! is_float($value)) {\n    $value = (float) $value;\n}","typeGuard":"function arrayKeyIsFloat(array $array, string $key): bool {\n    return is_float(Arr::get($array, $key));\n}","tryCatchPattern":"try {\n    $price = Arr::float($order, 'totals.grand', 0.0);\n} catch (\\InvalidArgumentException $e) {\n    $price = (float) Arr::get($order, 'totals.grand', 0);\n}","preventionTips":["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."],"tags":["collections","arrays","type-mismatch","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}