Skip to main content

Module format_utils

Module format_utils 

Source
Expand description

Formatting helpers for monetary amounts, rates, and decimal numbers. Formatting helpers for monetary amounts, rates, and decimal numbers.

All functions accept raw integer representations — cents for monetary values and scaled integers for rates — and return formatted Strings suitable for insertion into NF-e XML elements.

Functions§

format_cents
Format a cents integer to a decimal string with the given number of decimal places.
format_cents_2
Format a cents integer to a decimal string with 2 decimal places.
format_cents_10
Format a cents integer to a decimal string with 10 decimal places (for unit prices).
format_cents_or_none
Format an optional cents value to a decimal string, returning None when the input is None.
format_cents_or_zero
Format an optional cents value to a decimal string, defaulting to "0.00" (or "0. + n zeros") when the input is None.
format_decimal
Format a floating-point number with decimal_places decimal places.
format_rate
Format a rate stored as hundredths of a percent to a decimal string.
format_rate4
Format a PIS/COFINS rate stored as value × 10 000 to a 4-decimal string.
format_rate4_or_zero
Format an optional rate4 value (scaled by 10 000) to a 4-decimal string, defaulting to "0.0000" when the input is None.
format_rate_4
Format a rate (stored as hundredths) with 4 decimal places.