diff options
author | Jonah Lawrence <jonah@freshidea.com> | 2022-11-02 00:35:41 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 08:35:41 +0200 |
commit | 103c214dcf57e53f8f18b30f59947c9752c18ab2 (patch) | |
tree | 02785d54dfabe87f951d939321d5659686bc373a /babel/support.py | |
parent | f7af1b72e765278b3431de3f3b92c6b9a189b18e (diff) | |
download | babel-103c214dcf57e53f8f18b30f59947c9752c18ab2.tar.gz |
feat: Add `Format.compact_decimal` utility (#921)
Diffstat (limited to 'babel/support.py')
-rw-r--r-- | babel/support.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/babel/support.py b/babel/support.py index 80e9340..3efc003 100644 --- a/babel/support.py +++ b/babel/support.py @@ -18,7 +18,7 @@ from babel.core import Locale from babel.dates import format_date, format_datetime, format_time, \ format_timedelta from babel.numbers import format_decimal, format_currency, \ - format_percent, format_scientific + format_percent, format_scientific, format_compact_decimal class Format: @@ -108,6 +108,17 @@ class Format: """ return format_decimal(number, format, locale=self.locale) + def compact_decimal(self, number, format_type='short', fraction_digits=0): + """Return a number formatted in compact form for the locale. + + >>> fmt = Format('en_US') + >>> fmt.compact_decimal(123456789) + u'123M' + """ + return format_compact_decimal(number, format_type=format_type, + fraction_digits=fraction_digits, + locale=self.locale) + def currency(self, number, currency): """Return a number in the given currency formatted for the locale. """ |