Skip to content

Instantly share code, notes, and snippets.

@victorono
Created March 26, 2014 21:23
Show Gist options
  • Save victorono/9793873 to your computer and use it in GitHub Desktop.
Save victorono/9793873 to your computer and use it in GitHub Desktop.
Function that can round like this: 10 -> 10, 12 -> 10, 13 -> 15, 14 -> 15, 16 -> 15, 18 -> 20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django import template
register = template.Library()
@register.filter(name='round_step')
def round_step(x, base=5):
return int(base * round(float(x)/base))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment