-
-
Save eventuallyc0nsistent/1a69a7e265b642467e0338dc14cf34fb to your computer and use it in GitHub Desktop.
Angular filter to convert numbers to thousand suffixes (1234 > 1.2k)
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
""" | |
Source: https://gist.github.com/thewarpaint/889690aeb21a8dfd7aba | |
""" | |
from __future__ import division | |
def number_suffixes(number): | |
suffixes = ['k', 'M', 'G', 'T', 'P', 'E'] | |
if not isinstance(number, int): | |
return number | |
if number < 1000: | |
return number | |
exp = int(math.floor(math.log(number)/math.log(1000))) | |
result = '%.2f' % (number/math.pow(1000, exp)) + suffixes[exp - 1] | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment