Created
July 2, 2018 12:24
-
-
Save kevsersrca/32d0e9db7e486d2737c210ff5a8bc14d to your computer and use it in GitHub Desktop.
Bandwidth bytes to round size type
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
func BandwidthSize(bytes uint64) (float64, string) { | |
var tmp float64 = float64(bytes) | |
var s string = " " | |
bytes = uint64(tmp) | |
switch { | |
case bytes < uint64(2<<9): | |
case bytes < uint64(2<<19): | |
tmp = tmp / float64(2<<9) | |
s = "K" | |
case bytes < uint64(2<<29): | |
tmp = tmp / float64(2<<19) | |
s = "M" | |
case bytes < uint64(2<<39): | |
tmp = tmp / float64(2<<29) | |
s = "G" | |
case bytes < uint64(2<<49): | |
tmp = tmp / float64(2<<39) | |
s = "T" | |
} | |
return tmp, s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment