Files
intellecton/venv/lib/python3.12/site-packages/babel/__pycache__/numbers.cpython-312.pyc
T

793 lines
63 KiB
Plaintext
Raw Normal View History

Ë
jí÷ãóBdZddlmZddlZddlZddlZddlZddlmZm Z m
Z
m Z ddl m
Z
mZmZddlmZed«Zed«ZGd „d
e«Zd=d>d Zd=d?d Zd=d@d
Zd=dAdZ dB dCdZd=dDdZdEdZ dB dCdZe dF dGd«Ze dF dHd«Z dI dJdZ dK dLdZddœ dMdZ Gdde«Z! d=ddœ dNdZ" d=ddœ dNdZ# d=ddœ dNdZ$ d=ddœ dNdZ% d=ddœ dNd „Z& d=ddœ dNd!„Z' d= dOd"„Z(dPd#„Z)dQd$„Z* dRddœ dSd%„Z+d&dddd'œ dTd(„Z, dUd)„Z-Gd*„d+e.«Z/ dVddœ dWd,„Z0 dXd-„Z1d&dddd'œ dYd.„Z2 dRddœ dSd/„Z3 dZddœ d[d0„Z4Gd1„d2e5«Z6hd3£Z7ejpd4jse7««Z: d=ddœ d\d5„Z; d]ddœ d^d6„Z<d_d7„Z=ejpd8«Z>d`d9„Z?dad;„Z@Gd<„d:«ZAy)ba
babel.numbers
~~~~~~~~~~~~~
Locale dependent formatting and parsing of numeric data.
The default locale for the functions in this module is determined by the
following environment variables, in that order:
* ``LC_MONETARY`` for currency related functions,
* ``LC_NUMERIC``, and
* ``LC_ALL``, and
* ``LANG``
:copyright: (c) 2013-2026 by the Babel Team.
:license: BSD, see LICENSE for more details.
é)Ú annotationsN)ÚAnyÚLiteralÚcastÚoverload)ÚLocaleÚdefault_localeÚ
get_global)ÚLocaleDataDict)Ú LC_MONETARYÚ
LC_NUMERICr
cóeZdZdZddZy)ÚUnknownCurrencyErrorzMException thrown when a currency is requested for which no data is available.cóFtj|d|d«||_y)zkCreate the exception.
:param identifier: the identifier string of the unsupported currency
zUnknown currency ú.N)Ú ExceptionÚ__init__Ú
identifier)Úselfrs úP/home/antigravity/intellecton/venv/lib/python3.12/site-packages/babel/numbers.pyrzUnknownCurrencyError.__init__(s'ô ×ј4Ð#4°Z°NÀ!Ð!DÔ%ˆóN)rÚstrÚreturnÚNone)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r©rrrr%s
Ù%rrcó~|r(ttj|«j«Stt d««S)aLReturn a `set` of normalized currency codes.
.. versionadded:: 2.5.0
:param locale: filters returned currency codes by the provided locale.
Expected to be a locale instance or code. If no locale is
provided, returns the list of all currencies from all
locales.
Úall_currencies)ÚsetrÚparseÚ
currenciesr
©Úlocales rÚlist_currenciesr'2s2ñÜ”6—<< Ó'× ŒzÐ ,rcó4|t|«vr t|«y)aCheck the currency code is recognized by Babel.
Accepts a ``locale`` parameter for fined-grained validation, working as
the one defined above in ``list_currencies()`` method.
Raises a `UnknownCurrencyError` exception if the currency is unknown to Babel.
N)r'r©Úcurrencyr&s rÚvalidate_currencyr+Bs!ð " /rcób|rt|t«sy t||«y#t$rYywxYw)zxReturns `True` only if a currency is recognized by Babel.
This method always return a Boolean and never raise.
FT)Ú
isinstancerr+rr)s rÚ is_currencyr.Ns;ñ
œ: h´Ôðܘ( FÔ øô òÙðús "¢ .­.có`t|t«r|j«}t||«sy|S)zûReturns the normalized identifier of any currency code.
Accepts a ``locale`` parameter for fined-grained validation, working as
the one defined above in ``list_currencies()`` method.
Returns None if the currency is unknown to Babel.
N)r-rÚupperr.r)s rÚnormalize_currencyr1\s,ô(œCÔ Ø—>#ˆÜ x Ô Ø €Orcótj|xst«}|< |j|«}|j d}||vr||}||vr||Sd|vr|dS|jj||«S#tt
f$rd}YŒYwxYw)Return the name used by the locale for the specified currency.
>>> get_currency_name('USD', locale='en_US')
'US Dollar'
.. versionadded:: 0.9.4
:param currency: the currency code.
:param count: the optional count. If provided the currency name
will be pluralized to that number if possible.
:param locale: the `Locale` object or locale identifier.
Defaults to the system currency locale or numeric locale.
ÚotherÚcurrency_names_plural) rr#r Ú plural_formÚ
OverflowErrorÚ
ValueErrorÚ_datar$Úget)r*Úcountr&Úlocr5Ú plural_namesÚcurrency_plural_namess rÚget_currency_namer>kô$ ,‰,Ó
-€CØ ÐðŸ/™/¨%Ó0ˆ—y‘yÐ!8Ñ Ø  #Ø$0°Ñ$:Ð Ð,¨[ÑÐ,¨WÑ >‰>× Ñ ˜Ó 1øôœzÐ!ŠKð "ús¡A8Á8B  B cóptj|xst«jj ||«S)a4Return the symbol used by the locale for the specified currency.
>>> get_currency_symbol('USD', locale='en_US')
'$'
:param currency: the currency code.
:param locale: the `Locale` object or locale identifier.
Defaults to the system currency locale or numeric locale.
)rr#r Úcurrency_symbolsr9r)s rÚget_currency_symbolrAs+ô <‰<˜Ò-¤+Ó .× ?× CÀHÈhÓ WrcóHtd«}|j||d«dS)zÔReturn currency's precision.
Precision is the number of decimals found after the decimal point in the
currency's format pattern.
.. versionadded:: 2.5.0
:param currency: the currency code.
Úcurrency_fractionsÚDEFAULTr)r
r9)r*Ú
precisionss rÚget_currency_precisionrFšs*ôÐ1€JØ >‰>˜( J¨yÑ$9Ó :¸ =rcóÊtj|xst«}|$|j|«} |jd|S|jddS#t
$rYŒwxYw)
Return the unit pattern used for long display of a currency value
for a given locale.
This is a string containing ``{0}`` where the numeric part
should be substituted and ``{1}`` where the currency long display
name should be substituted.
>>> get_currency_unit_pattern('USD', locale='en_US', count=10)
'{0} {1}'
.. versionadded:: 2.7.0
:param currency: the currency code.
:param count: the optional count. If provided the unit
pattern for that number will be returned.
:param locale: the `Locale` object or locale identifier.
Defaults to the system currency locale or numeric locale.
Úcurrency_unit_patternsr3)rr#r r5r8Ú LookupError)r*r:r&r;r5s rÚget_currency_unit_patternrJ¨spô. ,‰,Ó
-€CØ ÐØ—o‘o eÓ ð Ø—9‘9Ð6°{Ñ
9‰9Ð .¨wÑ 7øô ò á ð ús²AÁ A"Á!A"cóy©Nr©Ú territoryÚ
start_dateÚend_dateÚtenderÚ
non_tenderÚinclude_detailss rÚget_territory_currenciesrTËsðrcóyrLrrMs rrTrTÖsðrcóHtd«}tjj«Šn*t tj«rj«ŠŠn*t tj«rj«Š|j |j
«d«}ˆˆfd}g} |D]m\}
} } }
| rtj| Ž} | rtj| Ž} |
r|s|
rŒ7|sŒ:|| | «sŒD|r| j|
| | |
dœ«Œ]| j|
«Œo| S)asReturns the list of currencies for the given territory that are valid for
the given date range. In addition to that the currency database
distinguishes between tender and non-tender currencies. By default only
tender currencies are returned.
The return value is a list of all currencies roughly ordered by the time
of when the currency became active. The longer the currency is being in
use the more to the left of the list it will be.
The start date defaults to today. If no end date is given it will be the
same as the start date. Otherwise a range can be defined. For instance
this can be used to find the currencies in use in Austria between 1995 and
2011:
>>> from datetime import date
>>> get_territory_currencies('AT', date(1995, 1, 1), date(2011, 1, 1))
['ATS', 'EUR']
Likewise it's also possible to find all the currencies in use on a
single date:
>>> get_territory_currencies('AT', date(1995, 1, 1))
['ATS']
>>> get_territory_currencies('AT', date(2011, 1, 1))
['EUR']
By default the return value only includes tender currencies. This
however can be changed:
>>> get_territory_currencies('US')
['USD']
>>> get_territory_currencies('US', tender=False, non_tender=True,
... start_date=date(2014, 1, 1))
['USN', 'USS']
.. versionadded:: 2.0
:param territory: the name of the territory to find the currency for.
:param start_date: the start date. If not given today is assumed.
:param end_date: the end date. If not given the start date is assumed.
:param tender: controls whether tender currencies should be included.
:param non_tender: controls whether non-tender currencies should be
included.
:param include_details: if set to `True`, instead of returning currency
codes the return value will be dictionaries
with detail information. In that case each
dictionary will have the keys ``'currency'``,
``'from'``, ``'to'``, and ``'tender'``.
Úterritory_currenciesrcó4|duxs|kxr |duxs|k\SrLr)ÚstartÚendrPrOs €€rÚ
_is_activez,get_territory_currencies.<locals>._is_active's*ø€Ø˜
Ò¨(Ñ!2ÒÀ¸Ò9YÈÈzÑHYÐZr)r*ÚfromÚtorQ)r
ÚdatetimeÚdateÚtodayr-r9r0Úappend)rNrOrPrQrRrSr$Úcursr[ÚresultÚ
currency_coderYrZÚ is_tenders `` rrTrTásù€ôrÐ3€JØÐÜ—]‘]×*‰
Ü × 1Ñ 1Ô 2Ø—_&ˆ
ØÐØÜ Hœh×/Ô 0Ø—==“?ˆà >‰>˜)Ÿ/™/Ó+¨RÓ 0€Dõ[ð€FØ04ò,ˆ
u˜c 9Ù Ü—M‘M 5Ð)ˆEÙ Ü—-‘- Ð%ˆCÙ
™6ª9ºÉ*Ø Ø õK
ñØ
à$1Ø %Ø!Ø"+ñ õð
˜,ð'-ð* €MrÚlatncó(|dk(r |jS|S)default)Údefault_numbering_system©r&Únumbering_systems rÚ_get_numbering_systemrlCsð˜9Ò×Ðr©rkcó‚t||«} |j|S#t$r}td|d|d«|d}~wwxYw)NzUnknown numbering system z for Locale r)rlÚnumber_symbolsÚKeyErrorÚUnsupportedNumberingSystemError)r&rkÚerrors rÚ_get_number_symbolsrsMs]ô
-¨VÐ5EÓðØ×$Ð%5Ñ6øÜ òÜ'Ð(8Ð'9¸ÀfÀXÈQÐ 
àð ûðúsŽ >¦9¹>cóeZdZdZy)rqzXException thrown when an unsupported numbering system is requested for the given Locale.N©rrrrrrrrqrq[sÙrrqcóvtj|xst«}t||¬«j dd«S)u Return the symbol used by the locale to separate decimal fractions.
>>> get_decimal_symbol('en_US')
'.'
>>> get_decimal_symbol('ar_EG', numbering_system='default')
'Ù«'
>>> get_decimal_symbol('ar_EG', numbering_system='latn')
'.'
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param numbering_system: The numbering system used for fetching the symbol. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
rmÚdecimalr©rr#r
rsr9rjs rÚget_decimal_symbolryas3ô&\‰\˜.¤JÓ
/€FÜ ˜vÐ8HÔ I× MÈiÐY\Ó ]rcóvtj|xst«}t||¬«j dd«S)Return the plus sign symbol used by the current locale.
>>> get_plus_sign_symbol('en_US')
'+'
>>> get_plus_sign_symbol('ar_EG', numbering_system='default')
'\u061c+'
>>> get_plus_sign_symbol('ar_EG', numbering_system='latn')
'\u200e+'
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param numbering_system: The numbering system used for fetching the symbol. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: if the numbering system is not supported by the locale.
rmÚplusSignú+rxrjs rÚget_plus_sign_symbolr}xs3ô&\‰\˜.¤JÓ
/€FÜ ˜vÐ8HÔ I× MÈjÐZ]Ó ^rcóvtj|xst«}t||¬«j dd«S)Return the plus sign symbol used by the current locale.
>>> get_minus_sign_symbol('en_US')
'-'
>>> get_minus_sign_symbol('ar_EG', numbering_system='default')
'\u061c-'
>>> get_minus_sign_symbol('ar_EG', numbering_system='latn')
'\u200e-'
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param numbering_system: The numbering system used for fetching the symbol. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: if the numbering system is not supported by the locale.
rmÚ minusSignú-rxrjs rÚget_minus_sign_symbolrs3ô&\‰\˜.¤JÓ
/€FÜ ˜vÐ8HÔ I× MÈkÐ[^Ó _rcóvtj|xst«}t||¬«j dd«S)Return the symbol used by the locale to separate mantissa and exponent.
>>> get_exponential_symbol('en_US')
'E'
>>> get_exponential_symbol('ar_EG', numbering_system='default')
'أس'
>>> get_exponential_symbol('ar_EG', numbering_system='latn')
'E'
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param numbering_system: The numbering system used for fetching the symbol. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: if the numbering system is not supported by the locale.
rmÚ exponentialÚErxrjs rÚget_exponential_symbolr…¦s3ô&\‰\˜.¤JÓ
/€FÜ ˜vÐ8HÔ I× MÈmÐ]`Ó arcóvtj|xst«}t||¬«j dd«S)Return the symbol used by the locale to separate groups of thousands.
>>> get_group_symbol('en_US')
','
>>> get_group_symbol('ar_EG', numbering_system='default')
'Ù¬'
>>> get_group_symbol('ar_EG', numbering_system='latn')
','
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param numbering_system: The numbering system used for fetching the symbol. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: if the numbering system is not supported by the locale.
rmÚgroupú,rxrjs rÚget_group_symbolr‰½s3ô&\‰\˜.¤JÓ
/€FÜ ˜vÐ8HÔ I× MÈgÐWZÓ [rcóvtj|xst«}t||¬«j dd«S)u Return the symbol used by the locale to represent infinity.
>>> get_infinity_symbol('en_US')
'∞'
>>> get_infinity_symbol('ar_EG', numbering_system='default')
'∞'
>>> get_infinity_symbol('ar_EG', numbering_system='latn')
'∞'
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param numbering_system: The numbering system used for fetching the symbol. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: if the numbering system is not supported by the locale.
rmÚinfinityu∞rxrjs rÚget_infinity_symbolrŒÔs3ô&\‰\˜.¤JÓ
/€FÜ ˜vÐ8HÔ I× MÈjÐZ_Ó `rcóTtjdtd¬«t||¬«S)Return the given number formatted for a specific locale.
>>> format_number(1099, locale='en_US') # doctest: +SKIP
'1,099'
>>> format_number(1099, locale='de_DE') # doctest: +SKIP
'1.099'
.. deprecated:: 2.6.0
Use babel.numbers.format_decimal() instead.
:param number: the number to format
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
z+Use babel.numbers.format_decimal() instead.é©Ú
stacklevelr%)ÚwarningsÚwarnÚDeprecationWarningÚformat_decimal)Únumberr&s rÚ
format_numberrës(ô(
‡MØõô
˜Ô 0rcóôt|tj«sJ|j«j «}t|j
t «r|j
dk\ryt|j
«S)zReturn maximum precision of a decimal instance's fractional part.
Precision is extracted from the fractional part only.
r)r-rwÚDecimalÚ normalizeÚas_tupleÚexponentÚintÚabs)r•Ú
decimal_tuples rÚget_decimal_precisionrŸsaô fœgŸo™oÔ  ×&×1€Mä m×,¬cÔ 2°m×6LÑ6LÐPQÒ6QØÜ ˆ}× &rcóxt|ttjf«sJtjd«| zS)z<Return minimal quantum of a number, as defined by precision.é
)r-rwr˜)Ú precisions rÚget_decimal_quantumr£s1ä i¤#¤w§¡Ð!7Ô  ?‰?˜  I  .rcó tj|xst«}||j|}t |«}|j |||||¬«S)Return the given decimal number formatted for a specific locale.
>>> format_decimal(1.2345, locale='en_US')
'1.234'
>>> format_decimal(1.2346, locale='en_US')
'1.235'
>>> format_decimal(-1.2346, locale='en_US')
'-1.235'
>>> format_decimal(1.2345, locale='sv_SE')
'1,234'
>>> format_decimal(1.2345, locale='de')
'1,234'
>>> format_decimal(1.2345, locale='ar_EG', numbering_system='default')
'1Ù«234'
>>> format_decimal(1.2345, locale='ar_EG', numbering_system='latn')
'1.234'
The appropriate thousands grouping and the decimal separator are used for
each locale:
>>> format_decimal(12345.5, locale='en_US')
'12,345.5'
By default the locale is allowed to truncate and round a high-precision
number by forcing its format pattern onto the decimal part. You can bypass
this behavior with the `decimal_quantization` parameter:
>>> format_decimal(1.2346, locale='en_US')
'1.235'
>>> format_decimal(1.2346, locale='en_US', decimal_quantization=False)
'1.2346'
>>> format_decimal(12345.67, locale='fr_CA', group_separator=False)
'12345,67'
>>> format_decimal(12345.67, locale='en_US', group_separator=True)
'12,345.67'
:param number: the number to format
:param format:
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param decimal_quantization: Truncate and round high-precision numbers to
the format pattern. Defaults to `True`.
:param group_separator: Boolean to switch group separator on/off in a locale's
number format.
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
©Údecimal_quantizationÚgroup_separatorrk)rr#r
Údecimal_formatsÚ
parse_patternÚapply©r•Úformatr&rkÚpatterns rr”r”s\ôp\‰\˜.¤JÓ
/€FØ
€~Ø×Ñ/ˆÜ˜#€GØ =‰=ØØØ ó ðrÚshort)Ú format_typer&Úfraction_digitsrkcóÞtj|xst«}|j|}t ||||«\}}||j
d}t
|«}|j||d|¬«S)uˆReturn the given decimal number formatted for a specific locale in compact form.
>>> format_compact_decimal(12345, format_type="short", locale='en_US')
'12K'
>>> format_compact_decimal(12345, format_type="long", locale='en_US')
'12 thousand'
>>> format_compact_decimal(12345, format_type="short", locale='en_US', fraction_digits=2)
'12.34K'
>>> format_compact_decimal(1234567, format_type="short", locale="ja_JP")
'123万'
>>> format_compact_decimal(2345678, format_type="long", locale="mk")
'2 милиони'
>>> format_compact_decimal(21000000, format_type="long", locale="mk")
'21 милион'
>>> format_compact_decimal(12345, format_type="short", locale='ar_EG', fraction_digits=2, numbering_system='default')
'12Ù«34\xa0ألÙ'
:param number: the number to format
:param format_type: Compact format to use ("short" or "long")
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param fraction_digits: Number of digits after the decimal point to use. Defaults to `0`.
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
NF©rk)rr#r
Úcompact_decimal_formatsÚ_get_compact_formatr¨)r•r&rkÚcompact_formatr¬r­s rÚformat_compact_decimalr¶`s}ôB\‰\˜.¤JÓ
/€FØ×3°KÑ@€NܰÀÈÓYN€FˆFà
€~Ø×Ñ-ˆÜ˜#€GØ =‰=ØØØ ó ðrc
óÐt|tj«stjt|««}|j «s|j «r|dfSd}t
|dDcgc]
}t|«Œc}d¬«D}t|«|k\sŒ|dt|«}t|«j}|dk(r||fSttj||d|jd«dz
zzz «}t||«}|jt|««} | |vrd} |dk(rd|vrd} t|«|| vrd} || t|«}|}||fS||fScc}w) zÑReturns the number after dividing by the unit and the format pattern to use.
The algorithm is described here:
https://www.unicode.org/reports/tr35/tr35-45/tr35-numbers.html#Compact_Number_Formats.
Nr3T)ÚreverseÚ0r¡éÚ1)r-rwr˜rÚis_nanÚ is_infiniteÚsortedrœrr­rr:Úroundr5)
r•r&ÚmÚ magnituder­Úroundedr5s
rr´r´sxô fœgŸo™oÔ ¤ V£ÓØ
‡}}„˜&×tˆØ
€Fܨ^¸GÑ-DÖœS EÈtÔˆ Ü ˆv‹;˜)Ó # ,¬S°«^Ñ<ˆ# +×3ˆ˜#Š~Øð( 6ˆ>Ðô#ÜØ˜)¨¨w¯}©}¸SÓ/AÀAÑ/EÑ(Fш
˜F OÓ4ˆGà ×,¬S°«[Ó9ˆKØ .Ñ% ؘŠ{˜s nÑ! Ü9~ ^°KÑ%@Ñ% Ø# KѰY³Ñ@ˆˆFØ Ø 6ˆ>Ðð7ð6 6ˆùò7FsÁ+E#cóeZdZdZy)ÚUnknownCurrencyFormatErrorz>Exception raised when an unknown currency format is requested.Nrurrr½sÚHrc
ótj|xst«}|dk(rt||||||||¬«S|r t |«} n |j
|} | j|||||||¬«S#t $rt|d«dwxYw)Return formatted currency value.
>>> format_currency(1099.98, 'USD', locale='en_US')
'$1,099.98'
>>> format_currency(1099.98, 'USD', locale='es_CO')
'US$1.099,98'
>>> format_currency(1099.98, 'EUR', locale='de_DE')
'1.099,98\xa0\u20ac'
>>> format_currency(1099.98, 'EGP', locale='ar_EG', numbering_system='default')
'\u200f1٬099٫98\xa0ج.م.\u200f'
The format can also be specified explicitly. The currency is
placed with the '¤' sign. As the sign gets repeated the format
expands (¤ being the symbol, ¤¤ is the currency abbreviation and
¤¤¤ is the full name of the currency):
>>> format_currency(1099.98, 'EUR', '\xa4\xa4 #,##0.00', locale='en_US')
'EUR 1,099.98'
>>> format_currency(1099.98, 'EUR', '#,##0.00 \xa4\xa4\xa4', locale='en_US')
'1,099.98 euros'
Currencies usually have a specific number of decimal digits. This function
favours that information over the given format:
>>> format_currency(1099.98, 'JPY', locale='en_US')
'\xa51,100'
>>> format_currency(1099.98, 'COP', '#,##0.00', locale='es_ES')
'1.099,98'
However, the number of decimal digits can be overridden from the currency
information, by setting the last parameter to ``False``:
>>> format_currency(1099.98, 'JPY', locale='en_US', currency_digits=False)
'\xa51,099.98'
>>> format_currency(1099.98, 'COP', '#,##0.00', locale='es_ES', currency_digits=False)
'1.099,98'
If a format is not specified the type of currency format to use
from the locale can be specified:
>>> format_currency(1099.98, 'EUR', locale='en_US', format_type='standard')
'\u20ac1,099.98'
When the given currency format type is not available, an exception is
raised:
>>> format_currency('1099.98', 'EUR', locale='root', format_type='unknown')
Traceback (most recent call last):
...
UnknownCurrencyFormatError: "'unknown' is not a known currency format type"
>>> format_currency(101299.98, 'USD', locale='en_US', group_separator=False)
'$101299.98'
>>> format_currency(101299.98, 'USD', locale='en_US', group_separator=True)
'$101,299.98'
You can also pass format_type='name' to use long display names. The order of
the number and currency name, along with the correct localized plural form
of the currency name, is chosen according to locale:
>>> format_currency(1, 'USD', locale='en_US', format_type='name')
'1.00 US dollar'
>>> format_currency(1099.98, 'USD', locale='en_US', format_type='name')
'1,099.98 US dollars'
>>> format_currency(1099.98, 'USD', locale='ee', format_type='name')
'us ga dollar 1,099.98'
By default the locale is allowed to truncate and round a high-precision
number by forcing its format pattern onto the decimal part. You can bypass
this behavior with the `decimal_quantization` parameter:
>>> format_currency(1099.9876, 'USD', locale='en_US')
'$1,099.99'
>>> format_currency(1099.9876, 'USD', locale='en_US', decimal_quantization=False)
'$1,099.9876'
:param number: the number to format
:param currency: the currency code
:param format: the format string to use
:param locale: the `Locale` object or locale identifier.
Defaults to the system currency locale or numeric locale.
:param currency_digits: use the currency's natural number of decimal digits
:param format_type: the currency format type to use
:param decimal_quantization: Truncate and round high-precision numbers to
the format pattern. Defaults to `True`.
:param group_separator: Boolean to switch group separator on/off in a locale's
number format.
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
Úname)r&Úcurrency_digitsr¦rkz$ is not a known currency format typeN©r*rk) rr#r Ú_format_currency_long_namer©Úcurrency_formatsrp)
r•r*r&rkr­s
rÚformat_currencyrËÁôP\‰\˜/¤KÓ
0€FàÜ Ø ØØØ+Ø!5Ø 
ð
ñÜ Ó'‰ð Ø×-¨kÑ:ˆGð =‰=ØØØØ ó ðøô ò Ü/Ð!EÐàð
ð ús ÁA,Á,Bc ót|t«r t|«n|}t|||¬«} t |||¬«}
|s|j
d}t
|«} | j|||||||¬«} | j| |
«S)N)r:r&) r-rÚfloatrJr>)
r•r*r&rkÚnumber_nÚ unit_patternÚ display_namer­Ú number_parts
rLs”ô(!+¨6´3Ô 7ŒuVŒ}¸V€Hô-¨X¸XÈfÔU€Lô% X°XÀfÔM€Lñ Ø×Ñ-ˆä˜#€Gà—-‘-ØØØØ ó€Kð × Ñ ˜{¨LÓ 9rcóötj|xst«} |j|}t
||||«\}}|
dt|«vr^|dD]V} |d| j}d|vrŒtjdd|«}tjdd|«j«}n| td «t|«}
|
j|||d
d
|¬ «S#t$r}t |d«|d}~wwxYw) uFormat a number as a currency value in compact form.
>>> format_compact_currency(12345, 'USD', locale='en_US')
'$12K'
>>> format_compact_currency(123456789, 'USD', locale='en_US', fraction_digits=2)
'$123.46M'
>>> format_compact_currency(123456789, 'EUR', locale='de_DE', fraction_digits=1)
'123,5\xa0Mio.\xa0€'
:param number: the number to format
:param currency: the currency code
:param format_type: the compact format type to use. Defaults to "short".
:param locale: the `Locale` object or locale identifier.
Defaults to the system currency locale or numeric locale.
:param fraction_digits: Number of digits after the decimal point to use. Defaults to `0`.
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
z, is not a known compact currency format typeNõ¤r3u [^0\s\¤]Úz(\s)\s+z\1zANo compact currency format found for the given number and locale.F)r*rk)rr#r Úcompact_currency_formatsrpr´rr­ÚreÚsubÚstripr7) r•r*r&rkrrr­s rÚformat_compact_currencyrÙ{s(ô8\‰\˜/¤KÓ
0€FðØ×Ñô
°ÀÈÓYN€FˆFà
€~˜¤S¨£[ÑÑ ˆ# ,¨YÑ?ˆFؘ6Ñä—VV˜L¨"¨fÓ5ˆFä—VV˜¨vÓ6×>ˆ ð ð€~ÜИFÓ#€GØ =‰=ØØØØØ
ó ðøô) ò܈oÐ 
àð ûðúsŸCà C8Ã$C3Ã3C8có tj|xst«}|s|jd}t |«}|j |||||¬«S)Return formatted percent value for a specific locale.
>>> format_percent(0.34, locale='en_US')
'34%'
>>> format_percent(25.1234, locale='en_US')
'2,512%'
>>> format_percent(25.1234, locale='sv_SE')
'2\xa0512\xa0%'
>>> format_percent(25.1234, locale='ar_EG', numbering_system='default')
'2Ù¬512%'
The format pattern can also be specified explicitly:
>>> format_percent(25.1234, '#,##0\u2030', locale='en_US')
'25,123‰'
By default the locale is allowed to truncate and round a high-precision
number by forcing its format pattern onto the decimal part. You can bypass
this behavior with the `decimal_quantization` parameter:
>>> format_percent(23.9876, locale='en_US')
'2,399%'
>>> format_percent(23.9876, locale='en_US', decimal_quantization=False)
'2,398.76%'
>>> format_percent(229291.1234, locale='pt_BR', group_separator=False)
'22929112%'
>>> format_percent(229291.1234, locale='pt_BR', group_separator=True)
'22.929.112%'
:param number: the percent number to format
:param format:
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param decimal_quantization: Truncate and round high-precision numbers to
the format pattern. Defaults to `True`.
:param group_separator: Boolean to switch group separator on/off in a locale's
number format.
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
Nr¥)rr#r
Úpercent_formatsr©s rÚformat_percentrܸsZôf\‰\˜.¤JÓ
/€FÙ Ø×Ñ-ˆÜ˜#€GØ =‰=ØØØ ó ðrcóžtj|xst«}|s|jd}t |«}|j ||||¬«S)upReturn value formatted in scientific notation for a specific locale.
>>> format_scientific(10000, locale='en_US')
'1E4'
>>> format_scientific(10000, locale='ar_EG', numbering_system='default')
'1أس4'
The format pattern can also be specified explicitly:
>>> format_scientific(1234567, '##0.##E00', locale='en_US')
'1.23E06'
By default the locale is allowed to truncate and round a high-precision
number by forcing its format pattern onto the decimal part. You can bypass
this behavior with the `decimal_quantization` parameter:
>>> format_scientific(1234.9876, '#.##E0', locale='en_US')
'1.23E3'
>>> format_scientific(1234.9876, '#.##E0', locale='en_US', decimal_quantization=False)
'1.2349876E3'
:param number: the number to format
:param format:
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param decimal_quantization: Truncate and round high-precision numbers to
the format pattern. Defaults to `True`.
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
Nr²)rr#r
Úscientific_formatsr©)r•r&rkr­s rÚformat_scientificrßøsWôL\‰\˜.¤JÓ
/€FÙ Ø×*¨4ÑܘFÓ#€GØ =‰=ØØØ ó ðrcó&eZdZdZddˆfd
ZˆxZS)ÚNumberFormatErrorz>Exception raised when a string cannot be parsed into a number.có2t||«||_yrL)ÚsuperrÚ suggestions)rÚmessageräÚ __class__s €rrzNumberFormatError.__init__-sø€Ü
јÔ&ˆÕrrL)rzlist[str] | Nonerr)rrrrrÚ
__classcell__)s@r*sø„Ù'r>õ õ ú ú|cót||¬«}|tvr/||vr+tj|«rtj ||«} t |j
|d««S#t$r}t|d«|d}~wwxYw)Parse localized number string into an integer.
>>> parse_number('1,099', locale='en_US')
1099
>>> parse_number('1.099', locale='de_DE')
1099
When the given string cannot be parsed, an exception is raised:
>>> parse_number('1.099,98', locale='de')
Traceback (most recent call last):
...
NumberFormatError: '1.099,98' is not a valid number
:param string: the string to parse
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:return: the parsed number
:raise `NumberFormatError`: if the string can not be converted to a number
:raise `UnsupportedNumberingSystemError`: if the numbering system is not supported by the locale.
rmz is not a valid numberN) r‰Ú SPACE_CHARSÚSPACE_CHARS_REÚsearchr×Úreplacer7)Ústringr&rkÚ group_symbolÚves rÚ parse_numberrô<sˆô8$ FÐ=MÔN€Lð œ Ñ  Ñ × !   ×# L°&Ó9ˆðMÜ6—>> Ó4øÜ òMÜ 6 *Ð,BÐ CÓDÈ"ÐLûðMúsÁA!Á! A>Á*A9Á9A>cóDtj|xst«}t||¬«}t ||¬«}|s7|t
vr/||vr+t j|«rt j||«} tj|j|d«j|d««}|r||vr™t||d|¬«}||k7r…|t||«k7rv tj|j|d«j|d««} t| |d|¬«}
|
|k(rt|d|d |g¬
«t|d|d |
d ||
g¬
«|S#tj$r}t|d«|d}~wwxYw#tj$r}t|d|d |g¬
«|d}~wwxYw) u6Parse localized decimal string into a decimal.
>>> parse_decimal('1,099.98', locale='en_US')
Decimal('1099.98')
>>> parse_decimal('1.099,98', locale='de')
Decimal('1099.98')
>>> parse_decimal('12 345,123', locale='ru')
Decimal('12345.123')
>>> parse_decimal('1Ù¬099Ù«98', locale='ar_EG', numbering_system='default')
Decimal('1099.98')
When the given string cannot be parsed, an exception is raised:
>>> parse_decimal('2,109,998', locale='de')
Traceback (most recent call last):
...
NumberFormatError: '2,109,998' is not a valid decimal number
If `strict` is set to `True` and the given string contains a number
formatted in an irregular way, an exception is raised:
>>> parse_decimal('30.00', locale='de', strict=True)
Traceback (most recent call last):
...
NumberFormatError: '30.00' is not a properly formatted decimal number. Did you mean '3.000'? Or maybe '30,00'?
>>> parse_decimal('0.00', locale='de', strict=True)
Traceback (most recent call last):
...
NumberFormatError: '0.00' is not a properly formatted decimal number. Did you mean '0'?
:param string: the string to parse
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:param strict: controls whether numbers formatted in a weird way are
accepted or rejected
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise NumberFormatError: if the string can not be converted to a
decimal number
:raise UnsupportedNumberingSystemError: if the numbering system is not supported by the locale.
rmrz is not a valid decimal numberNF)r&rkz: is not a properly formatted decimal number. Did you mean ú?)z ? Or maybe )rr#r
r‰ryr×rwr˜ÚInvalidOperationrár”Ú$_remove_trailing_zeros_after_decimal) r&ÚstrictrkÚdecimal_symbolÚparsedÚexcÚproperÚ
parsed_altÚ
proper_alts rÚ
parse_decimalrkô`\‰\˜.¤JÓ
/€FÜ# FÐ=MÔN€LÜÐAQÔR€Ná Øœ Ñ  Ñ × !   ×# L°&ÓðVÜ §¡° ¸bÓ!A×!IÑ!IÈ.ÐZ]Ó!^Ó_ˆñ, Ø ØØ!&Ø
ˆð   Ô*NÈvÐWeÓ*fÒ fð
Ü$Ÿ_™_Ø—NN >°2Ó6×>¸|ÈSÓ
ôØ!Ø).Ø%5ô 
ð  Ò!˜%(Ø(. ð4à%+ ðô !˜%(Ø(. ¸Z¸NÈ!ðMà%+¨ZÐ$8ôðð
€MøôO × VÜ 6 *Ð,JÐ KÓLÐRUÐUûðVûô×
Ü!$Ø$* :¨Qð0à!' ôðð ûð
ús0Á25EÃ5E2ÅE/ÅE*Å*E/Å2FÆFÆFcón|j|«\}}}|r|jd«}|r||z|zS|S|S)
Remove trailing zeros from the decimal part of a numeric string.
This function takes a string representing a numeric value and a decimal symbol.
It removes any trailing zeros that appear after the decimal symbol in the number.
If the decimal part becomes empty after removing trailing zeros, the decimal symbol
is also removed. If the string does not contain the decimal symbol, it is returned unchanged.
:param string: The numeric string from which to remove trailing zeros.
:type string: str
:param decimal_symbol: The symbol used to denote the decimal point.
:type decimal_symbol: str
:return: The numeric string with trailing zeros removed from its decimal part.
:rtype: str
Example:
>>> _remove_trailing_zeros_after_decimal("123.4500", ".")
'123.45'
>>> _remove_trailing_zeros_after_decimal("100.000", ".")
'100'
>>> _remove_trailing_zeros_after_decimal("100", ".")
'100'
)Ú partitionÚrstrip)Ú integer_partÚ decimal_parts rÔsLð0%+×$4Ñ$4°^Ó$DÑ!€L!Ø*¨3Ó/ˆ Ù Ø .Ñ0°<Ñ Ðà €MrzJ(?P<prefix>(?:[^'0-9@#.,]|'[^']*')*)(?P<number>[0-9@#.,E+]*)(?P<suffix>.*)có¶t|«}|jd«}|dk(ry||z
dz
}|d| dz
jd«}|dk(r||fS||z
|z
dz
}||fS)z¹Parse primary and secondary digit grouping
>>> parse_grouping('##')
(1000, 1000)
>>> parse_grouping('#,###')
(3, 3)
>>> parse_grouping('#,####,###')
(3, 4)
éÿÿÿÿ)éèr NrŽ)ÚlenÚrfind)ÚwidthÚg1Úg2s rÚparse_groupingrþsxô
F€EØ
€BØ ˆR‚xØØ a‰€BØ
ˆ9ˆbˆS1‰Wˆ× Ñ ˜CÓ €BØ ˆR‚xØ2ˆvˆ
Ø b‰˜1Ñ €BØ
ˆrˆ6€MrÚ
NumberPatternc ó(t|t«r|Sd}|}d|vr.|jdd«\}}||«\}}}||«\}}} n||«\}}}d|}|} d|vr|jdd«\}}
nd}
d|vrd|vrd |vr td
«d|vr|j dd«\} } n|} d } d }
|
| «}|
| «}|
r+|
j d
«}|
j
d
«}
|
|
«}nd}d}t| «}t|||f|| f||||||« S)zParse number format patternscóltj|«}|td|«|j«S)NzInvalid number pattern )Ú_number_pattern_rerïr7Úgroups)r­Úrvs rÚ
_match_numberz$parse_pattern.<locals>._match_numbers6Ü
×
& 
/ˆØ
ˆ:ÜÐ6°w°kÐ y‰y‹{Ðrú;rºr€r„@rz5Significant digit patterns can not contain "@" or "0"rÔcóhdx}}|D]&}|dvr |dz
}|dz
}Œ|dk(r|dz
}Œ|dk(rŒ#||fS||fS)z(Calculate the min and max allowed digitsrz@0rºú#rˆr)r ÚminÚmaxÚcs rÚparse_precisionz&parse_pattern.<locals>.parse_precision6sdàˆ
ˆˆcØò ˆAØD‰yØq‘Øq‘Øc’Øq‘Øc’ØàØCˆxˆð ðCˆxˆrr|)r-rÚsplitr7ÚrsplitÚ
startswithÚlstripr)r­rÚ pos_patternÚ neg_patternÚ
pos_prefixr•Ú
pos_suffixÚ
neg_prefixrÚ
neg_suffixÚexpÚintegerÚfractionrÚint_precÚ frac_precÚexp_plusÚexp_precÚgroupings rsmä'œ=Ôˆòð €Kð ˆg~Ø#*§=¡=°°aÓ#8Ñ ˆ [Ù)6°{Ó)CÑ&ˆ
F˜JÙ$1°+Ó$>Ñ!ˆ
Azá)6°{Ó)CÑ&ˆ
F˜˜˜ Ð%ˆ
؈
Ø
ˆf—l‘l 3¨Ó*‰ ˆàˆØ
ˆf}˜ ¨3°&©=ÜÐ
ˆf"ŸM™M¨#¨qÓˆàˆØˆò
ñ˜'€HÙ Ó)€IÙ
Ø—>> &ˆØj‰j˜oˆÙ" '‰àˆØˆÜ˜&€HÜ ØØ  Ø  ØØØØØØó
ð
rcóeZdZ d
ddZddZddZddœ ddZ dddœ ddZdd „Z dd
Z dd Z
d
dd Z y)rNc
ó¬||_||_||_| |_||_||_||_||_||_|j«|_
yrL) r­ÚprefixÚsuffixÚnumber_patternr1r-r.r0r/Ú
compute_scaleÚscale)
rr­r4r5r1r-r.r0r/r6s
rrzNumberPattern.__init__]sTðˆŒ ØˆŒ ؈Œ ØÔØ ˆŒ
Ø ˆŒ
Ø"ˆŒØ ˆŒ
Ø ˆŒ
Ø×)ˆ
rcóNdt|«jd|jdS)<rêú>)Útyperr­)rs rÚ__repr__zNumberPattern.__repr__us'Ø”4˜“:×' ¯©Ð(8¸Ð:rcó¾d}ddj|j|jz«vrd}|Sddj|j|jz«vrd}|S)uReturn 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.
rú%rÔu‰é)Újoinr4r5)rr8s rr7zNumberPattern.compute_scalexs]ðˆØ "—''˜$Ÿ+™+¨¯ © Ñ ˆEðˆ ðb—g‘g˜dŸk™k¨D¯K©KÑ
ˆˆ rrfrmcóR|j«}|t|«z}|j«dk(sJtdt|j«g«dz
}||z
}|t| «z}d}|dkrt ||¬«}n|j r
t||¬«}t|«}|||fS)z=Returns normalized scientific notation components of a value.rrm) Úadjustedr£rrr-rr/r}r)rÚvaluer&rkr*Ú
lead_shiftÚexp_signs rÚscientific_notation_elementsz*NumberPattern.scientific_notation_elements†ðn‰nÓˆØÔ+¨CÓØ~‰~Ó 1Ò
˜!œS §¡Ó1°AÑ
؈ØÔ+¨Z¨KÓðˆØ Š7Ü,¨VÐFVÔW‰HØ
]Š]Ü+¨FÐEUÔVˆ#hˆàc˜#rc ó¼t|tj«stjt|««}|j |j