Fixed #22798 -- `pluralize()` now adds plural_suffix for any `1 < d < 2`

Thanks Odd_Bloke for the report.
This commit is contained in:
Moayad Mardini 2014-06-10 21:28:32 +03:00 committed by Tim Graham
parent f97c53c098
commit 868ff4e37c
2 changed files with 6 additions and 1 deletions

View File

@ -934,7 +934,7 @@ def pluralize(value, arg='s'):
singular_suffix, plural_suffix = bits[:2]
try:
if int(value) != 1:
if float(value) != 1:
return plural_suffix
except ValueError: # Invalid string that's not a number.
pass

View File

@ -654,6 +654,11 @@ class DefaultFiltersTests(TestCase):
self.assertEqual(pluralize(1), '')
self.assertEqual(pluralize(0), 's')
self.assertEqual(pluralize(2), 's')
# Ticket #22798
self.assertEqual(pluralize(0.5), 's')
self.assertEqual(pluralize(1.5), 's')
self.assertEqual(pluralize(decimal.Decimal(1)), '')
self.assertEqual(pluralize(decimal.Decimal(0)), 's')
self.assertEqual(pluralize(decimal.Decimal(2)), 's')