2020-10-26 21:14:26 +08:00
|
|
|
package numberutils
|
|
|
|
|
|
2021-01-19 16:14:09 +08:00
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
2020-10-26 21:14:26 +08:00
|
|
|
|
|
|
|
|
func FormatInt64(value int64) string {
|
|
|
|
|
return strconv.FormatInt(value, 10)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func FormatInt(value int) string {
|
|
|
|
|
return strconv.Itoa(value)
|
|
|
|
|
}
|
2021-01-19 16:14:09 +08:00
|
|
|
|
|
|
|
|
func FormatBytes(bytes int64) string {
|
|
|
|
|
if bytes < 1024 {
|
|
|
|
|
return FormatInt64(bytes) + "B"
|
|
|
|
|
} else if bytes < 1024*1024 {
|
|
|
|
|
return fmt.Sprintf("%.2fK", float64(bytes)/1024)
|
|
|
|
|
} else if bytes < 1024*1024*1024 {
|
|
|
|
|
return fmt.Sprintf("%.2fM", float64(bytes)/1024/1024)
|
|
|
|
|
} else if bytes < 1024*1024*1024*1024 {
|
|
|
|
|
return fmt.Sprintf("%.2fG", float64(bytes)/1024/1024/1024)
|
|
|
|
|
} else {
|
|
|
|
|
return fmt.Sprintf("%.2fP", float64(bytes)/1024/1024/1024/1024)
|
|
|
|
|
}
|
|
|
|
|
}
|