mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
add bytes
This commit is contained in:
parent
0cfd3888b8
commit
c2795104e5
1 changed files with 16 additions and 0 deletions
16
src/utils/bytes.go
Normal file
16
src/utils/bytes.go
Normal 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])
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue