Skip to content

formatting

Helpers for formatting values displayed in the Streamlit interface.

format_currency(value)

Format a numeric value as whole-dollar currency.

Parameters:

Name Type Description Default
value float

Numeric value to format.

required

Returns:

Type Description
str

Dollar-formatted string without decimal cents.

Source code in src/refi_calculator/web/formatting.py
10
11
12
13
14
15
16
17
18
19
def format_currency(value: float) -> str:
    """Format a numeric value as whole-dollar currency.

    Args:
        value: Numeric value to format.

    Returns:
        Dollar-formatted string without decimal cents.
    """
    return f"${value:,.0f}"

format_months(value)

Describe a month count alongside its equivalent in years.

Parameters:

Name Type Description Default
value float | int | None

Number of months to convert.

required

Returns:

Type Description
str

Human-friendly string or "N/A" when value is missing.

Source code in src/refi_calculator/web/formatting.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def format_months(value: float | int | None) -> str:
    """Describe a month count alongside its equivalent in years.

    Args:
        value: Number of months to convert.

    Returns:
        Human-friendly string or "N/A" when value is missing.
    """
    if value is None:
        return "N/A"
    months = int(value)
    years = value / 12
    return f"{months} mo ({years:.1f} yr)"

format_optional_currency(value)

Format an optional numeric value as currency, falling back to N/A.

Parameters:

Name Type Description Default
value float | None

Optional numeric value.

required

Returns:

Type Description
str

Formatted currency or "N/A" when no value is present.

Source code in src/refi_calculator/web/formatting.py
22
23
24
25
26
27
28
29
30
31
32
33
def format_optional_currency(value: float | None) -> str:
    """Format an optional numeric value as currency, falling back to N/A.

    Args:
        value: Optional numeric value.

    Returns:
        Formatted currency or "N/A" when no value is present.
    """
    if value is None:
        return "N/A"
    return format_currency(value)

format_savings_delta(value)

Invert savings sign to match user-facing storytelling.

Parameters:

Name Type Description Default
value float

Value representing savings.

required

Returns:

Type Description
str

Signed string reflecting the UX messaging used in the GUI.

Source code in src/refi_calculator/web/formatting.py
65
66
67
68
69
70
71
72
73
74
75
def format_savings_delta(value: float) -> str:
    """Invert savings sign to match user-facing storytelling.

    Args:
        value: Value representing savings.

    Returns:
        Signed string reflecting the UX messaging used in the GUI.
    """
    prefix = "-" if value >= 0 else "+"
    return f"{prefix}{format_currency(abs(value))}"

format_signed_currency(value)

Format a signed value with explicit plus/minus.

Parameters:

Name Type Description Default
value float

Value to format with sign.

required

Returns:

Type Description
str

Signed currency string to highlight deltas.

Source code in src/refi_calculator/web/formatting.py
52
53
54
55
56
57
58
59
60
61
62
def format_signed_currency(value: float) -> str:
    """Format a signed value with explicit plus/minus.

    Args:
        value: Value to format with sign.

    Returns:
        Signed currency string to highlight deltas.
    """
    prefix = "+" if value >= 0 else "-"
    return f"{prefix}{format_currency(abs(value))}"