format
Get a number (as a number or string), and return it as a string, using formats defined as arguments:
* decimal_sep: Decimal separator symbol (for example ".")
* decimal_pos: Number of decimal positions
* grouping: Number of digits in every group limited by thousand separator.
For non-uniform digit grouping, it can be a sequence with the number
of digit group sizes following the format used by the Python locale
module in locale.localeconv() LC_NUMERIC grouping (e.g. (3, 2, 0)).
* thousand_sep: Thousand separator symbol (for example ",")
def format(
number: Union[int, float, Decimal, str],
decimal_sep: str,
decimal_pos: int = None,
grouping: Union[int, Iterable[int]] = 0,
thousand_sep: str = "",
force_grouping: bool = False,
use_l10n: bool = None
) - > string
Get a number (as a number or string), and return it as a string, using formats defined as arguments.
Parameters
| Name | Type | Description |
|---|---|---|
| number | Union[int, float, Decimal, str] | The numeric value or string representation of a number to be formatted. |
| decimal_sep | str | The character used as the decimal separator symbol (e.g., "."). |
| decimal_pos | int = None | The number of decimal positions to include; pads with zeros or truncates as necessary. |
| grouping | Union[int, Iterable[int]] = 0 | The number of digits in every group limited by the thousand separator, or a sequence of group sizes following locale.localeconv() rules. |
| thousand_sep | str = "" | The character used as the thousand separator symbol (e.g., ","). |
| force_grouping | bool = False | If True, applies the thousand separator grouping regardless of localization settings. |
| use_l10n | bool = None | Determines if localization settings should be used to trigger grouping; defaults to True if not provided. |
Returns
| Type | Description |
|---|---|
string | The formatted number as a string, including the specified separators, grouping, and decimal precision. |