Every line of 'python format currency' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
14 @register.filter(name='currency') 15 def currency_formatter(value, currency=None): 16 """ 17 Format decimal value as currency 18 """ 19 try: 20 value = D(value) 21 except (TypeError, InvalidOperation): 22 return "" 23 # Using Babel's currency formatting 24 # http://babel.pocoo.org/docs/api/numbers/#babel.numbers.format_currency 25 currency = currency or settings.ACCOUNTING_DEFAULT_CURRENCY 26 kwargs = { 27 'currency': currency, 28 'format': getattr(settings, 'CURRENCY_FORMAT', None), 29 'locale': to_locale(get_language()), 30 } 31 return format_currency(value, **kwargs)
32 def __str__(self): 33 return ("{} {}".format(self.amount, self.currency._symbol))
194 def amount_string(amount: int, currency: str) -> str: 195 zero_decimal_currencies = ["bif", "djf", "jpy", "krw", "pyg", "vnd", "xaf", 196 "xpf", "clp", "gnf", "kmf", "mga", "rwf", "vuv", "xof"] 197 if currency in zero_decimal_currencies: 198 decimal_amount = str(amount) # nocoverage 199 else: 200 decimal_amount = '{0:.02f}'.format(float(amount) * 0.01) 201 202 if currency == 'usd': # nocoverage 203 return '$' + decimal_amount 204 return decimal_amount + ' {}'.format(currency.upper())