mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
add bytecountdecimal
This commit is contained in:
parent
005a206460
commit
3685a887b8
1 changed files with 13 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue