-
-
Save kernelkaribou/6d008f8739d32de645a04ea533824afb to your computer and use it in GitHub Desktop.
Quick Bandwidth Format function
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
#Formatting of data sent in bytes to label in largest size | |
def format_data_type(i, type): | |
loop = 0 | |
current_num = i | |
last_num = 0 | |
if type == "net": | |
label = ["Bps", "KBps", "MBps", "GBps"] | |
if type == "size": | |
label = ["B", "KB", "MB", "GB", "TB"] | |
while(True): | |
last_num = current_num | |
current_num = current_num/1024.0 | |
if(current_num < 1): | |
return '{0:0.0f}{1}'.format(last_num, label[loop]) | |
loop = loop + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment