Skip to content

Instantly share code, notes, and snippets.

@kevsersrca
Created July 2, 2018 12:24
Show Gist options
  • Save kevsersrca/32d0e9db7e486d2737c210ff5a8bc14d to your computer and use it in GitHub Desktop.
Save kevsersrca/32d0e9db7e486d2737c210ff5a8bc14d to your computer and use it in GitHub Desktop.
Bandwidth bytes to round size type
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