1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | from django import template
import math
register = template.Library()
def sigdig(value, digits = 3):
order = int(math.floor(math.log10(math.fabs(value))))
places = digits - order - 1
if places > 0:
fmtstr = "%%.%df" % (places)
else:
fmtstr = "%.0f"
return fmtstr % (round(value, places))
register.filter('sigdig', sigdig)
|
More like this
- HTML to text filter by MasonM 3 years, 6 months ago
- Calendar table by fauxparse 3 years, 9 months ago
- Jinja2 Django integration by mathwizard 3 years, 4 months ago
- Convert newlines into <p> and </p> tags by jheasly 4 years, 10 months ago
- Bitwise operator queryset filter by hgeerts@osso.nl 1 year, 9 months ago
Comments