-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currency normalization #478
Comments
Am I understanding this correctly:
If so, you can adapt the innards of from babel import Locale
from babel.numbers import decimal
def custom_format_currency(value, currency, locale):
value = decimal.Decimal(value)
locale = Locale.parse(locale)
pattern = locale.currency_formats['standard']
force_frac = ((0, 0) if value == int(value) else None)
return pattern.apply(value, locale, currency=currency, force_frac=force_frac)
print(custom_format_currency('2.50', 'EUR', 'fi'))
print(custom_format_currency('2.00', 'EUR', 'fi')) outputs
|
@szewczykmira : That's more or less what I did with my |
This is addressed by #494. |
@akx can this zero-stripping feature be added as an option to |
Bumping this -- I have a use case where I sometimes want to display currency without any decimals, but not have a solution that requires a different format string for each locale. |
In my project I need to format currency so that it won't display digital decimals if they are equal to zero. Right now I'm doing it by replacing
.00
to.##
in current locale pattern and passing it as format toformat_currency
and settingcurrency_digits=False
. It works like charm when price has 0 or 2 decimal digits, but I'm not sure how to handle prices with 3 decimal digits. Can I safely replace.00
with. + '#' * decimal_digits
or it will cause problems I'm not aware of? Or maybe there is better solution for that?The text was updated successfully, but these errors were encountered: