impl/python/format_money_tick.py
551 bytes · the Python implementation · view raw
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
import math
from .math_round_float import round_float ← from math.round-float ^1.0.0 · built alongside by fune
from .money_amount import money ← from money.amount ^1.0.0 · built alongside by fune
from .money_format import format_money ← from money.format ^1.0.0 · built alongside by fune
def format_money_tick(minor: float, currency: str) -> str:
"""A money-axis tick: rounded half away from zero to a whole minor unit,
then printed by money.format."""
if isinstance(minor, bool) or not isinstance(minor, (int, float)) or not math.isfinite(minor):
raise ValueError("minor must be a finite number, received %r" % (minor,))
return format_money(money(int(round_float(minor, 0)), currency))