fmt_percent()

Format a proportion as a percentage.

Usage

Source

fmt_percent(
    x,
    *,
    decimals=1,
)

Parameters

x: float

The proportion to format, where 1 is 100%.

decimals: int = 1
The number of decimal places.

Returns

str
The formatted percentage.

Examples

A proportion of 0.256 is 25.6%:

from tinytab import fmt_percent

fmt_percent(0.256)
'25.6%'

Use decimals= to change the precision:

fmt_percent(0.256, decimals=0)
'26%'