{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Config/Repository.php#L121-L157","documentation":"Thrown by Config\\Repository::float(string $key) when the stored value is not a float. The check is is_float($value); note that an int value (e.g. 5) is NOT a float in PHP's strict sense and will fail this check, as will numeric strings, bools, and null. InvalidArgumentException reports the key and the actual type.","triggerScenarios":"Config::float('payment.fee') where the config stores 5 (int), '5.0' (string), or null; reading an env-backed value without a float cast.","commonSituations":"Config file stores a literal integer where a float was expected; env returns a string; missing key with no float default. The int-vs-float strictness is the most common surprise.","solutions":["Cast the value to float in the config file: (float) env('PAYMENT_FEE', 0.0).","Provide a float default: Config::float('payment.fee', 0.0).","Ensure the stored literal is a float (e.g. 5.0, not 5) when you control the config."],"exampleFix":"// before\n// config: 'fee' => env('PAYMENT_FEE', 5),  // int default\n$fee = Config::float('payment.fee');\n// after\n// config: 'fee' => (float) env('PAYMENT_FEE', 5.0),\n$fee = Config::float('payment.fee', 5.0);","handlingStrategy":"type-guard","validationCode":"$value = Config::get('payment.fee');\nif (! is_float($value)) {\n    throw new \\InvalidArgumentException('payment.fee must be float');\n}","typeGuard":"function configIsFloat(string $key): bool {\n    return is_float(Config::get($key));\n}","tryCatchPattern":"try {\n    $fee = Config::float('payment.fee');\n} catch (\\InvalidArgumentException $e) {\n    $fee = 0.0; // safe default\n}","preventionTips":["Cast env-backed values to float in config files: (float) env('KEY', 0.0).","Remember an int literal (5) is NOT a float — write 5.0 when needed.","Provide a float default to Config::float() to cover missing keys."],"tags":["config","type-safety","env","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}