> Has anyone tried to use pluralize template tag with a float value? I
> am thinking of submitting a patch to support this functionality.
> 
> For instance, using the value 1.5 returns a singular suffix from
> pluralize. I am implementing a real estate web application where a
> house could have 1.5 bathrooms, for example.

I suspect the pluralize filter is casting to an int which throws 
away the fractional part.  I'd clone the pluralize filter and 
make a custom one that uses a "floating point 
equals-within-epsilon" comparison:

   EPSILON = 0.0000001 # some arbitrarily small precision
   def floats_equal(f1, f2):
     return abs(f1-f2) < EPSILON

   register = template.Library()
   @register.filter(name="oneish")
   def oneish(value):
     return floats_equal(1.0, float(value))

...
   #####  template #####
   <p>This house has
   {{ house.bathrooms }}
    bathroom{{ house.bathrooms|oneish|pluralize }}
   </p>

The above is off-the-cuff & untested, but should be fairly close 
to an accurate implementation.  It also abuses the fact that 
"True == 1" which might be nice to make a little more explicit.

-tim







--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to