Chapter XV: internationalization and localization -locale: cultural currency localization API-

15.2.2 currency
can be seen from the preceding sample output, changing the localized environment will update currency symbol, but also to change the partition of the integer and fractional part of the character. Examples of this loop process a plurality of different locale, for each locale, a monetary value are formatted print positive and negative monetary value.

import locale

sample_locales = [
    ('USA','en_US'),
    ('France','fr_FR'),
    ('Spain','es_ES'),
    ('Portugal','pt_PT'),
    ('Poland','pl_PL'),
    ]

for name,loc in sample_locales:
    locale.setlocale(locale.LC_ALL,loc)
    print('{:>10}: {:>10} {:>10}'.format(
        name,
        locale.currency(1234.56),
        locale.currency(-1234.56),
        ))

Guess you like

Origin blog.csdn.net/weixin_43193719/article/details/94831440