mirror of
https://github.com/wonli/aqi.git
synced 2025-10-09 02:20:03 +08:00
init
This commit is contained in:
18
utils/format/format_byte.go
Normal file
18
utils/format/format_byte.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package format
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func Bites(size float64) string {
|
||||
unit := []string{"b", "kb", "mb", "gb", "tb", "pb"}
|
||||
s := math.Floor(math.Log(size) / math.Log(1024))
|
||||
i := int(s)
|
||||
|
||||
if i < len(unit) {
|
||||
return fmt.Sprintf("%.2f %s", size/math.Pow(1024, s), unit[i])
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%f %s", size, unit[0])
|
||||
}
|
Reference in New Issue
Block a user