The number module provides functionality to format numbers for different locales. This includes arbitrary numbers as well as currency.
Return formatted percent value for a specific locale.
>>> format_percent(0.34, locale='en_US')
u'34%'
>>> format_percent(25.1234, locale='en_US')
u'2,512%'
>>> format_percent(25.1234, locale='sv_SE')
u'2\xa0512\xa0%'
The format pattern can also be specified explicitly:
>>> format_percent(25.1234, u'#,##0\u2030', locale='en_US')
u'25,123\u2030'
Parameters: |
|
---|
Return value formatted in scientific notation for a specific locale.
>>> format_scientific(10000, locale='en_US')
u'1E4'
The format pattern can also be specified explicitly:
>>> format_scientific(1234567, u'##0E00', locale='en_US')
u'1.23E06'
Parameters: |
|
---|
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
Traceback (most recent call last):
...
NumberFormatError: '1.099,98' is not a valid number
Parameters: |
|
---|---|
Returns: | the parsed number |
Raises NumberFormatError: | |
if the string can not be converted to a number |
Parse 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')
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
Traceback (most recent call last):
...
NumberFormatError: '2,109,998' is not a valid decimal number
Parameters: |
|
---|---|
Raises NumberFormatError: | |
if the string can not be converted to a decimal number |
Exception raised when a string cannot be parsed into a number.
Return the name used by the locale for the specified currency.
>>> get_currency_name('USD', locale='en_US')
u'US Dollar'
New in version 0.9.4.
Parameters: |
|
---|
Return the symbol used by the locale for the specified currency.
>>> get_currency_symbol('USD', locale='en_US')
u'$'
Parameters: |
|
---|
Return the symbol used by the locale to separate decimal fractions.
>>> get_decimal_symbol('en_US')
u'.'
Parameters: | locale – the Locale object or locale identifier |
---|
Return the plus sign symbol used by the current locale.
>>> get_plus_sign_symbol('en_US')
u'+'
Parameters: | locale – the Locale object or locale identifier |
---|
Return the plus sign symbol used by the current locale.
>>> get_minus_sign_symbol('en_US')
u'-'
Parameters: | locale – the Locale object or locale identifier |
---|