FinancialPlatform / app /utils /formatters.py
Dmitry Beresnev
feat: restructure to multi-page app with modular architecture
f7323a3
raw
history blame contribute delete
754 Bytes
"""Data formatting utilities for the financial dashboard."""
import pandas as pd
def format_financial_value(value) -> str:
"""Format financial values with appropriate units."""
if pd.isna(value):
return "N/A"
if abs(value) >= 1e9:
return f"${value/1e9:.2f}B"
elif abs(value) >= 1e6:
return f"${value/1e6:.2f}M"
else:
return f"${value:.2f}"
def format_percentage(value: float, decimals: int = 2) -> str:
"""Format percentage values."""
if pd.isna(value):
return "N/A"
return f"{value:.{decimals}f}%"
def format_currency(value: float, decimals: int = 2) -> str:
"""Format currency values."""
if pd.isna(value):
return "N/A"
return f"${value:,.{decimals}f}"