diff --git a/utils.py b/utils.py index ad7f28f8dba..5e1b964debc 100644 --- a/utils.py +++ b/utils.py @@ -323,6 +323,17 @@ def env_int(key: str, default: int = 0) -> int: return default +def env_float(key: str, default: float = 0.0) -> float: + """Read an environment variable as a float, with fallback.""" + raw = os.getenv(key, "").strip() + if not raw: + return default + try: + return float(raw) + except (ValueError, TypeError): + return default + + def env_bool(key: str, default: bool = False) -> bool: """Read an environment variable as a boolean.""" return is_truthy_value(os.getenv(key, ""), default=default)