Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Define a function to scale b/Kb/Mb/Gb/Tb/Pb/Eb/Zb/Yb/WTFb and return it rounded to two decimal places
- def dataunits(x):
- try:
- #def bytes(x):
- if len(str(math.trunc(x))) <4 and len(str(math.trunc(x))) >= 1:
- return str(round(x,2)) + 'B'
- #def kilobytes(x):
- if len(str(math.trunc(x))) < 7 and len(str(math.trunc(x))) >= 4:
- return str(round(x/1000,2)) + 'KB'
- #def megabytes(x):
- if len(str(math.trunc(x))) < 10 and len(str(math.trunc(x))) >=7:
- return str(round(x/1000000,2)) + 'MB'
- #def gigabytes(x):
- if len(str(math.trunc(x))) < 13 and len(str(math.trunc(x))) >=10:
- return str(round(x/1000000000,2)) + 'GB'
- #def terabytes(x):
- if len(str(math.trunc(x))) < 16 and len(str(math.trunc(x))) >=13:
- return str(round(x/1000000000000,2)) + 'TB'
- #def petabytes(x):
- if len(str(math.trunc(x))) < 19 and len(str(math.trunc(x))) >=16:
- return str(round(x/1000000000000000,2)) + 'PB'
- #def exabytes(x):
- if len(str(math.trunc(x))) < 22 and len(str(math.trunc(x))) >=19:
- return str(round(x/1000000000000000000,2)) + 'EB'
- #def zettabytes(x):
- if len(str(math.trunc(x))) < 25 and len(str(math.trunc(x))) >=22:
- return str(round(x/1000000000000000000000,2)) + 'ZB'
- #def yottabytes(x):
- if len(str(math.trunc(x))) < 28 and len(str(math.trunc(x))) >=25:
- return str(round(x/1000000000000000000000000,2)) + 'YB'
- #def whatthefuckabytes(x):
- if len(str(math.trunc(x))) >= 28:
- return str(round(x/1000000000000000000000000000,2)) + 'WTFB'
- except SyntaxError:
- return 'NaN'
- except NameError:
- return 'NaN'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement