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
- Converts an integer or floating-point number or a string to a string containing the delimiter character (default comma) after every delimeter_count digits (by default 3 digits) by pikhovkin 1 year, 2 months ago
- FloatField with safe expression parsing by joelegner 3 years, 2 months ago
- Calendar table by fauxparse 5 years, 1 month ago
- Time ranges like 7-9 p.m. by sgb 5 years, 4 months ago
- Paginator Tag by insin 6 years, 2 months ago
Comments