How to format currency using Locale module














































How to format currency using Locale module



Format Currency:

earlier we learned how to format and parse a number using locale module if you haven't read about it you can click the previous button at this article. Locale module provides a built- in function named currency(), to format any input number .The output comes with the symbol of the currency or a text. Let's take an example for en_SG
# get current locale
locale.currency(694531.88)
# $694531.88
locale.currency(694531.88, grouping=True)
# $694,531.88
locale.currency(694531.88, grouping=True, international=True)
# SGD694,531.88

Aside from the number input, the function currency() also accepts three additional parameters :

     1)grouping (if set to True, the grouping is done with the value; the default value is False),

     2)symbol (if set to True, the returned string includes the currency symbol; the default value is True)

      3)international (if set to True, the international currency symbol is used; the default value is False).










Comments