Download app/utils/formatters.py from ResearchEngineering/FinancialPlatform: direct link, hf CLI and curl.
- Browser
- Download file 754 Bytes
-
https://huggingface.co/spaces/ResearchEngineering/FinancialPlatform/resolve/cfe2c87e79de2fccfcf85b5b9fcd61517c233113/app/utils/formatters.py
- Command line
-
hf download hf://spaces/ResearchEngineering/FinancialPlatform@cfe2c87e79de2fccfcf85b5b9fcd61517c233113/app/utils/formatters.py
-
curl -L -o formatters.py https://huggingface.co/spaces/ResearchEngineering/FinancialPlatform/resolve/cfe2c87e79de2fccfcf85b5b9fcd61517c233113/app/utils/formatters.py
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}" | |