fmt

Human-readable number and string formatting utilities.

Import

import fmt

Functions

fmt.number(n: float, decimals: int) -> str

Format number with fixed decimal places.

fmt.hex(n: int) -> str

Format integer as hex string, e.g. "0xff".

fmt.bin(n: int) -> str

Format integer as binary string, e.g. "0b1010".

fmt.pad(s: str, n: int) -> str

Right-pad string to width n with spaces.

fmt.comma(n: float) -> str

Format number with comma thousand separators, e.g. "1,000,000".

fmt.filesize(n: int) -> str

Human-readable file size, e.g. "1.2 MB".

fmt.ordinal(n: int) -> str

Ordinal string, e.g. "1st", "2nd", "3rd", "11th".

fmt.pluralize(word: str, n: int) -> str

Returns "{n} {word}" with the word pluralized if needed, e.g. "1 item" or "2 items".

Examples

scratch.xs