laravel/framework · error · InvalidArgumentException
Configuration value for key [%s] must be a float, %s given.
Error message
Configuration value for key [%s] must be a float, %s given.
What it means
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.
Source
Thrown at src/Illuminate/Config/Repository.php:139
return $value;
}
/**
* Get the specified float configuration value.
*
* @param string $key
* @param (\Closure():(float|null))|float|null $default
* @return float
*
* @throws \InvalidArgumentException
*/
public function float(string $key, $default = null): float
{
$value = $this->get($key, $default);
if (! is_float($value)) {
throw new InvalidArgumentException(
sprintf('Configuration value for key [%s] must be a float, %s given.', $key, gettype($value))
);
}
return $value;
}
/**
* Get the specified boolean configuration value.
*
* @param string $key
* @param (\Closure():(bool|null))|bool|null $default
* @return bool
*
* @throws \InvalidArgumentException
*/
public function boolean(string $key, $default = null): bool
{View on GitHub (pinned to bd6b5437e6)
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').
Example fix
// before
// 'rate' => env('PAYMENT_RATE'), // resolves to string "1.5"
config()->float('payment.rate');
// after
// 'rate' => (float) env('PAYMENT_RATE', 1.0),
config()->float('payment.rate', 1.0); Defensive patterns
Strategy: validation
Validate before calling
$v = config('payment.rate');
if (! is_float($v)) {
// cast or fix source; note int literals also fail is_float()
} Type guard
function isFloatConfig(\Illuminate\Config\Repository $c, string $key): bool
{
return is_float($c->get($key));
} Try / catch
try {
$rate = config()->float('payment.rate', 1.0);
} catch (\InvalidArgumentException $e) {
$rate = 1.0;
logger()->warning($e->getMessage());
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Configuration value for key [%s] must be an integer, %s give
- Configuration value for key [%s] must be a boolean, %s given
- Configuration value for key [%s] must be an array, %s given.
- Configuration value for key [%s] must be a string, %s given.
- This cache store does not support locks.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/771101f1e289f224.json.
Report an issue: GitHub.