from __future__ import annotations

import math
from typing import Any


def finite_number(value: Any, default: float | None = None) -> float | None:
    """Return a finite float, or default (None means JSON null)."""
    if value is None or value == "":
        return default
    try:
        number = float(value)
    except (TypeError, ValueError):
        return default
    if not math.isfinite(number):
        return default
    return number


def round4(value: float | None) -> float | None:
    if value is None:
        return None
    return round(float(value), 4)
