0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

add bytes

This commit is contained in:
Zack Scholl 2019-04-11 12:57:32 -07:00
parent 0cfd3888b8
commit c2795104e5

16
src/utils/bytes.go Normal file
View file

@ -0,0 +1,16 @@
package utils
import "fmt"
func ByteCountDecimal(b int64) string {
const unit = 1000
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp])
}