diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/humanize/templatetags/humanize.py | 5 | ||||
| -rw-r--r-- | django/template/defaultfilters.py | 2 | ||||
| -rw-r--r-- | django/utils/translation/__init__.py | 5 |
3 files changed, 9 insertions, 3 deletions
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index 194c7e8fbb..31880846f0 100644 --- a/django/contrib/humanize/templatetags/humanize.py +++ b/django/contrib/humanize/templatetags/humanize.py @@ -10,7 +10,7 @@ from django.utils.safestring import mark_safe from django.utils.timezone import is_aware, utc from django.utils.translation import ( gettext as _, gettext_lazy, ngettext, ngettext_lazy, npgettext_lazy, - pgettext, + pgettext, round_away_from_one, ) register = template.Library() @@ -158,7 +158,8 @@ def intword(value): large_number = 10 ** exponent if value < large_number * 1000: new_value = value / large_number - return _check_for_i18n(new_value, *converters(new_value)) + rounded_value = round_away_from_one(new_value) + return _check_for_i18n(new_value, *converters(rounded_value)) return value diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index d8fb0a5396..174d2a092d 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -812,7 +812,7 @@ def filesizeformat(bytes_): 102 bytes, etc.). """ try: - bytes_ = float(bytes_) + bytes_ = int(bytes_) except (TypeError, ValueError, UnicodeDecodeError): value = ngettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} return avoid_wrapping(value) diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py index 8f3e3396a4..e48c7d245d 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -4,6 +4,7 @@ Internationalization support. import re import warnings from contextlib import ContextDecorator +from decimal import ROUND_UP, Decimal from django.utils.autoreload import autoreload_started, file_changed from django.utils.deprecation import RemovedInDjango40Warning @@ -332,3 +333,7 @@ trim_whitespace_re = re.compile(r'\s*\n\s*') def trim_whitespace(s): return trim_whitespace_re.sub(' ', s.strip()) + + +def round_away_from_one(value): + return int(Decimal(value - 1).quantize(Decimal('0'), rounding=ROUND_UP)) + 1 |
