Last active
February 29, 2016 21:57
-
-
Save eads/6734e0fdd73fd58c721c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal, ROUND_DOWN | |
def percent_filter(value): | |
""" | |
Format percentage | |
""" | |
if value == 0: | |
return '0%' | |
elif value == 100: | |
return '100%' | |
elif value > 0 and value < 1: | |
return '<1%' | |
else: | |
return '{:.1f}%'.format(Decimal(value).quantize(Decimal('.1'), rounding=ROUND_DOWN)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment