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

  1. Cast in the config file: return (float) env('PAYMENT_RATE', 1.0);.
  2. Pass a float default at call site: config()->float('payment.rate', 1.0).
  3. Ensure the stored value is a real float — an integer literal 1 must become 1.0.
  4. 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

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


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/771101f1e289f224.json. Report an issue: GitHub.