Spaces:
Running
Running
File size: 840 Bytes
90531db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | """Helper utility functions."""
import pycountry
def get_country_name(country_code: str) -> str:
"""
Convert ISO country code to full country name.
Args:
country_code: Two-letter ISO country code (e.g., 'US')
Returns:
Full country name or the original code if not found
"""
try:
country = pycountry.countries.get(alpha_2=country_code)
return country.name if country else country_code
except (KeyError, AttributeError):
return country_code
def format_percentage(value: float, decimals: int = 2) -> float:
"""
Format a percentage value to specified decimal places.
Args:
value: The percentage value
decimals: Number of decimal places (default: 2)
Returns:
Formatted percentage value
"""
return round(value, decimals)
|