Created
March 15, 2018 18:33
-
-
Save tobixen/d80f32f91eeb0d9789525996154c21a5 to your computer and use it in GitHub Desktop.
converting a number like 50000 into 50k, 1000000 into 1M, etc
This file contains hidden or 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 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