mirror of
https://github.com/schollz/croc.git
synced 2024-11-28 01:16:10 +03:00
add bytecountdecimal
This commit is contained in:
parent
005a206460
commit
3685a887b8
@ -96,3 +96,16 @@ func GetRandomName() string {
|
||||
result = mnemonicode.EncodeWordList(result, bs)
|
||||
return strings.Join(result, "-")
|
||||
}
|
||||
|
||||
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…
Reference in New Issue
Block a user