Skip to content

Instantly share code, notes, and snippets.

@johandalabacka
Created October 5, 2018 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johandalabacka/b59f9dee267444068ad933986616fa71 to your computer and use it in GitHub Desktop.
Save johandalabacka/b59f9dee267444068ad933986616fa71 to your computer and use it in GitHub Desktop.
number of bytes in human readable form
func humanFormat(bytes int64) string {
n := float64(bytes)
for _, unit := range []string{"", "Ki", "Mi", "Gi"} {
if math.Abs(n) < 1024.0 {
return fmt.Sprintf("%3.1f%sB", n, unit)
}
n /= 1024.0
}
return fmt.Sprintf("%.1fTiB", n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment