{"id":"771101f1e289f224","repo":"laravel/framework","slug":"configuration-value-for-key-s-must-be-a-float","errorCode":null,"errorMessage":"Configuration value for key [%s] must be a float, %s given.","messagePattern":"Configuration value for key \\[(.+?)\\] must be a float, (.+?) given\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Config/Repository.php","lineNumber":139,"sourceCode":"\n        return $value;\n    }\n\n    /**\n     * Get the specified float configuration value.\n     *\n     * @param  string  $key\n     * @param  (\\Closure():(float|null))|float|null  $default\n     * @return float\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function float(string $key, $default = null): float\n    {\n        $value = $this->get($key, $default);\n\n        if (! is_float($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Configuration value for key [%s] must be a float, %s given.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Get the specified boolean configuration value.\n     *\n     * @param  string  $key\n     * @param  (\\Closure():(bool|null))|bool|null  $default\n     * @return bool\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function boolean(string $key, $default = null): bool\n    {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Config/Repository.php#L121-L157","documentation":"Thrown by Repository::float() (src/Illuminate/Config/Repository.php:139) when the resolved value is not a PHP float. Note is_float() is strict: a plain int (e.g. 5) also fails, as does any numeric string from env.","triggerScenarios":"Calling config()->float('payment.follarRate') when the value is a string \"1.5\", an int 1, null, or an array. Defaults that are int-typed also fail because is_float(1) === false.","commonSituations":"Developers store decimals as env strings; the typed accessor rejects them. Common when migrating config consumers to the new float() accessor or when an integer-valued rate (e.g. 1) is stored where a float is expected.","solutions":["Cast in the config file: return (float) env('PAYMENT_RATE', 1.0);.","Pass a float default at call site: config()->float('payment.rate', 1.0).","Ensure the stored value is a real float — an integer literal 1 must become 1.0.","If string is acceptable, use string() and cast in code: (float) config()->string('payment.rate')."],"exampleFix":"// before\n// 'rate' => env('PAYMENT_RATE'),  // resolves to string \"1.5\"\nconfig()->float('payment.rate');\n\n// after\n// 'rate' => (float) env('PAYMENT_RATE', 1.0),\nconfig()->float('payment.rate', 1.0);","handlingStrategy":"validation","validationCode":"$v = config('payment.rate');\nif (! is_float($v)) {\n    // cast or fix source; note int literals also fail is_float()\n}","typeGuard":"function isFloatConfig(\\Illuminate\\Config\\Repository $c, string $key): bool\n{\n    return is_float($c->get($key));\n}","tryCatchPattern":"try {\n    $rate = config()->float('payment.rate', 1.0);\n} catch (\\InvalidArgumentException $e) {\n    $rate = 1.0;\n    logger()->warning($e->getMessage());\n}","preventionTips":["Store floats as 1.0 not 1 in config to satisfy strict is_float().","Cast in config files: (float) env('KEY', 1.0).","Provide a float default at the call site."],"tags":["config","type-coercion","env","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}