This commit is contained in:
ideaa
2024-06-18 18:08:39 +08:00
parent af402cc224
commit b9be165fd2
132 changed files with 7964 additions and 0 deletions

View 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])
}