"""Number formatting helpers."""


def format_isk(amount) -> str:
    """Abbreviate an ISK amount EVE-style: K / M / B / T.

    Up to 2 decimals, trailing zeros stripped. Examples:
        23_000_000      -> "23M ISK"
        1_500_000_000   -> "1.5B ISK"
        149_000_000_000 -> "149B ISK"
        750             -> "750 ISK"
    """
    amount = int(amount)
    for unit, suffix in (
        (1_000_000_000_000, "T"),
        (1_000_000_000, "B"),
        (1_000_000, "M"),
        (1_000, "K"),
    ):
        if amount >= unit:
            value = f"{amount / unit:.2f}".rstrip("0").rstrip(".")
            return f"{value}{suffix} ISK"
    return f"{amount:,} ISK"
