from django.template import Node, Library

register = Library()

@register.filter('percentage')
def percentage(value, total):
  try:
    percentage = float(value) / float(total) * 100
  except ZeroDivisionError:
    percentage = 0
  return '<abbr title="%s/%s">%s%%</abbr>' % (value, total, percentage)

from django.template import Node, Library

register = Library()

@register.filter('percentage')
def percentage(value, total):
  try:
    percentage = int(value) / int(total) * 100
  except ZeroDivisionError:
    percentage = 0
  return '<abbr title="%s/%s">%s%%</abbr>' % (value, total, percentage)

--- 
+++ 
@@ -5,7 +5,7 @@
 @register.filter('percentage')
 def percentage(value, total):
   try:
-    percentage = int(value) / int(total) * 100
+    percentage = float(value) / float(total) * 100
   except ZeroDivisionError:
     percentage = 0
   return '<abbr title="%s/%s">%s%%</abbr>' % (value, total, percentage)
Fix % only showing 0 or 100%, everything between goes to 0%.


Autoconverted from SVN (revision:1548)
