class documentation

class NumberPattern: (source)

View In Hierarchy

Undocumented

Method __init__ Undocumented
Method __repr__ Undocumented
Method apply Renders into a string a number following the defined pattern.
Method compute_scale Return the scaling factor to apply to the number before rendering.
Method scientific_notation_elements Returns normalized scientific notation components of a value.
Instance Variable exp_plus Undocumented
Instance Variable exp_prec Undocumented
Instance Variable frac_prec Undocumented
Instance Variable grouping Undocumented
Instance Variable int_prec Undocumented
Instance Variable number_pattern Undocumented
Instance Variable pattern Undocumented
Instance Variable prefix Undocumented
Instance Variable scale Undocumented
Instance Variable suffix Undocumented
Method _format_frac Undocumented
Method _format_int Undocumented
Method _format_significant Undocumented
Method _quantize_value Undocumented
def __init__(self, pattern: str, prefix: tuple[str, str], suffix: tuple[str, str], grouping: tuple[int, int], int_prec: tuple[int, int], frac_prec: tuple[int, int], exp_prec: tuple[int, int]|None, exp_plus: bool|None, number_pattern: str|None = None): (source)

Undocumented

def __repr__(self) -> str: (source)

Undocumented

def apply(self, value: (float|decimal.Decimal)|str, locale: (Locale|str)|None, currency: str|None = None, currency_digits: bool = True, decimal_quantization: bool = True, force_frac: tuple[int, int]|None = None, group_separator: bool = True): (source)

Renders into a string a number following the defined pattern. Forced decimal quantization is active by default so we'll produce a number string that is strictly following CLDR pattern definitions. :param value: The value to format. If this is not a Decimal object, it will be cast to one. :type value: decimal.Decimal|float|int :param locale: The locale to use for formatting. :type locale: str|babel.core.Locale :param currency: Which currency, if any, to format as. :type currency: str|None :param currency_digits: Whether or not to use the currency's precision. If false, the pattern's precision is used. :type currency_digits: bool :param decimal_quantization: Whether decimal numbers should be forcibly quantized to produce a formatted output strictly matching the CLDR definition for the locale. :type decimal_quantization: bool :param force_frac: DEPRECATED - a forced override for `self.frac_prec` for a single formatting invocation. :return: Formatted decimal string. :rtype: str

def compute_scale(self) -> Literal[0, 2, 3]: (source)

Return the scaling factor to apply to the number before rendering. Auto-set to a factor of 2 or 3 if presence of a ``%`` or ``‰`` sign is detected in the prefix or suffix of the pattern. Default is to not mess with the scale at all and keep it to 0.

def scientific_notation_elements(self, value: decimal.Decimal, locale: (Locale|str)|None) -> tuple[decimal.Decimal, int, str]: (source)

Returns normalized scientific notation components of a value.

exp_plus = (source)

Undocumented

exp_prec = (source)

Undocumented

frac_prec = (source)

Undocumented

grouping = (source)

Undocumented

int_prec = (source)

Undocumented

number_pattern = (source)

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

def _format_frac(self, value: str, locale: (Locale|str)|None, force_frac: tuple[int, int]|None = None) -> str: (source)

Undocumented

def _format_int(self, value: str, min: int, max: int, locale: (Locale|str)|None) -> str: (source)

Undocumented

def _format_significant(self, value: decimal.Decimal, minimum: int, maximum: int) -> str: (source)

Undocumented

def _quantize_value(self, value: decimal.Decimal, locale: (Locale|str)|None, frac_prec: tuple[int, int], group_separator: bool) -> str: (source)

Undocumented