This commit is contained in:
coward
2024-08-06 14:49:05 +08:00
parent da7ffc9343
commit 4cc3c075ed
423 changed files with 115 additions and 7294 deletions

View File

@@ -1,7 +1,9 @@
package utils
import (
"fmt"
"github.com/dustin/go-humanize"
"math"
"math/big"
)
@@ -20,3 +22,23 @@ func (flowCalculation) Parse(b int64) string {
b2 := big.Int{}
return humanize.BigBytes(b2.SetInt64(b))
}
// PrettyByteSizeGB
// @description:
// @param b
// @return string
func PrettyByteSizeGB(b int) string {
bf := float64(b)
ks := []string{"", "Ki", "Mi", "Gi"}
for i, unit := range ks {
if math.Abs(bf) < 1024.0 {
return fmt.Sprintf("%3.1f%sB", bf, unit)
}
if i+1 >= len(ks) {
return fmt.Sprintf("%3.1f%sB", bf, unit)
}
bf /= 1024.0
}
return fmt.Sprintf("%.1fYiB", bf)
}