12 lines
434 B
Python
12 lines
434 B
Python
from decimal import Decimal
|
|
|
|
|
|
def number_fmt(value, precision: int = 2) -> str:
|
|
value = Decimal(str(value))
|
|
precision = max(precision, -value.normalize().as_tuple().exponent)
|
|
return f"{value:,.{precision}f}".replace(",", "X").replace(".", ",").replace("X", ".")
|
|
|
|
|
|
def money_fmt(value, currency: str = "EUR") -> str:
|
|
return f"{Decimal(str(value)):,.2f} {currency}".replace(",", "X").replace(".", ",").replace("X", ".")
|