fmt_number()

Format a number with a fixed number of decimal places and a thousands separator.

Usage

Source

fmt_number(
    x,
    *,
    decimals=2,
    sep_mark=",",
)

Parameters

x: float

The number to format.

decimals: int = 2

The number of decimal places.

sep_mark: str = ","
The character used to separate groups of thousands.

Returns

str
The formatted number.

Examples

By default, numbers get two decimal places and a comma between groups of thousands:

from tinytab import fmt_number

fmt_number(1234567.891)
'1,234,567.89'

Use decimals= to change the precision, and sep_mark= for a different separator:

fmt_number(1234567.891, decimals=0, sep_mark=" ")
'1 234 568'