Digits¶
arapy.digits ¶
Convert, parse and format numbers in Latin, Arabic-Indic and Persian digits.
to_latin_digits ¶
Replace Arabic-Indic and Persian digits with Latin digits.
to_arabic_digits ¶
Replace Latin and Persian digits with Arabic-Indic digits.
to_persian_digits ¶
Replace Latin and Arabic-Indic digits with Persian digits.
parse_number ¶
Parse a number written in any digit set into an exact Decimal.
٬ is always a thousands separator and ٫ always a decimal mark. , . and ، can be
either, and when the text alone cannot tell ("1,250"), pass decimal to say which one
is the decimal mark; otherwise InvalidNumberError is raised. A ٫ in the text is the
decimal mark even when decimal names another one.
format_number ¶
format_number(
value: int | Decimal | str,
*,
digits: DigitSet = "latin",
grouping: str | None = ",",
decimal: str = ".",
places: int | None = None,
) -> str
Format a number with the given digit set, thousands separator and decimal mark.
places pads the fraction to that many digits. A value with more significant decimal
places raises InvalidNumberError: numbers are never rounded.
format_percent ¶
format_percent(
value: int | Decimal | str,
*,
digits: DigitSet = "latin",
grouping: str | None = ",",
decimal: str = ".",
places: int | None = None,
) -> str
Format a fraction as a percentage with the ٪ sign: Decimal("0.25") → "25٪".