I can't figure out how to set my currency to 0 decimals. for now it always puts .00 behind my currency.
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
damn = locale.currency(self.damn, grouping=True).replace('$','') + " Dmn"
self.damn is always an integer.
It seems like you are just interested in grouping. You don't need to use the currency function for this. Use locale.format():
import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
damn = '{0} Dmn'.format(locale.format('%d', self.damn, True))
And if you don't depend on the locale stuff, you can group the number with string.format(), too:
# Comma as separator
damn = '{:,} Dmn'.format(self.damn)
# Locale aware separator
damn = '{:n} Dmn'.format(self.damn)
The output is a string so add [:-3] to the end it:
a = locale.currency(num, grouping=True)[:-3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With