blob: 9b3aa97612a977cf1286d7f20d151f95f9df2e56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package common
import "fmt"
func PrettyBytes(b uint64) string {
if b < 1000 {
return fmt.Sprintf("%d Byte", b)
}
if b < 1000_000 {
return fmt.Sprintf("%.2f KiB", float64(b)/1024)
}
if b < 1000_000_000 {
return fmt.Sprintf("%.2f MiB", float64(b)/1024/1024)
}
if b < 1000_000_000_000 {
return fmt.Sprintf("%.2f GiB", float64(b)/1024/1024/1024)
}
return fmt.Sprintf("%.2f TiB", float64(b)/1024/1024/1024/1024)
}
|