{"record":{"id":"abfe78749c398e91","repo":"laravel/framework","slug":"cache-value-for-key-s-must-be-a-float-s-given","errorCode":null,"errorMessage":"Cache value for key [%s] must be a float, %s given.","messagePattern":"Cache value for key \\[(.+?)\\] must be a float, (.+?) given\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Cache/Repository.php","lineNumber":307,"sourceCode":"     * @param  (\\Closure():(float|null))|float|null  $default\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function float($key, $default = null): float\n    {\n        $key = enum_value($key);\n\n        $value = $this->get($key, $default);\n\n        if (is_float($value)) {\n            return $value;\n        }\n\n        if (filter_var($value, FILTER_VALIDATE_FLOAT) !== false) {\n            return (float) $value;\n        }\n\n        throw new InvalidArgumentException(\n            sprintf('Cache value for key [%s] must be a float, %s given.', $key, gettype($value))\n        );\n    }\n\n    /**\n     * Retrieve a boolean item from the cache.\n     *\n     * @param  \\UnitEnum|string  $key\n     * @param  (\\Closure():(bool|null))|bool|null  $default\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function boolean($key, $default = null): bool\n    {\n        $key = enum_value($key);\n\n        $value = $this->get($key, $default);\n","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Cache/Repository.php#L289-L325","documentation":"Thrown by Repository::float() when the value is not a real float and cannot be coerced by filter_var(FILTER_VALIDATE_FLOAT). is_float() runs first; note that an integer (e.g. 5) is NOT a float in PHP, but filter_var will coerce integer-strings. Pure ints stored in cache will fail unless they are float-typed.","triggerScenarios":"Calling Cache::float('key') with a stored int (not float), bool, array, object, non-numeric string, or null.","commonSituations":"Storing a price as an integer cents value and reading as float; cache miss without default; storing 'NaN' or empty strings.","solutions":["Pass a float default: Cache::float('key', 0.0).","Store as float at write time: Cache::put('rate', (float) $rate).","Cast integer sources to float before storing."],"exampleFix":"// before\n$rate = Cache::float('tax.rate'); // throws if stored int\n// after\n$rate = Cache::float('tax.rate', 0.0);","handlingStrategy":"validation","validationCode":"$raw = Cache::get($key);\nif ($raw !== null && ! is_float($raw) && filter_var($raw, FILTER_VALIDATE_FLOAT) === false) {\n    // normalize\n}\n$val = Cache::float($key, 0.0);","typeGuard":"function isCacheFloatable(mixed $value): bool {\n    return is_float($value) || filter_var($value, FILTER_VALIDATE_FLOAT) !== false;\n}","tryCatchPattern":"try {\n    $rate = Cache::float('rate');\n} catch (\\InvalidArgumentException $e) {\n    $rate = 0.0;\n}","preventionTips":["Cast numeric sources to float before Cache::put().","Pass a float default to typed reads.","Remember is_float() rejects plain ints; store true floats."],"tags":["cache","type-mismatch","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}