Skip to content

Instantly share code, notes, and snippets.

@tobixen
Created March 15, 2018 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobixen/d80f32f91eeb0d9789525996154c21a5 to your computer and use it in GitHub Desktop.
Save tobixen/d80f32f91eeb0d9789525996154c21a5 to your computer and use it in GitHub Desktop.
converting a number like 50000 into 50k, 1000000 into 1M, etc
from math import log10
import sys
def print_si(number):
units = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
thousands = int(log10(number)//3)
base = number//1000**thousands
print("%d %s" % (base, units[thousands]))
if __name__ == '__main__':
print_iso(int(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment