"""Return on Investment."""

from __future__ import annotations


def roi(benefits_pv: float, costs_pv: float) -> float:
    """
    Return on Investment as a fraction.

    ``ROI = (Benefits − Costs) / Costs``

    Costs here are expressed as a positive present-value amount (the absolute
    cost). Returns ``0.0`` when costs are zero (rather than dividing by zero).

    Example::

        >>> round(roi(101_696_791, 22_983_076), 2)   # Amazon Connect: 342%
        3.42
    """
    if costs_pv <= 0:
        return 0.0
    return (benefits_pv - costs_pv) / costs_pv


def roi_percentage(benefits_pv: float, costs_pv: float) -> float:
    """ROI as a percentage (e.g. 342.0 for 342%)."""
    return roi(benefits_pv, costs_pv) * 100.0
