3 Star 17 Fork 4

eyebluecn/tank

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util_string.go 595 Bytes
一键复制 编辑 原始数据 按行查看 历史
zicla 提交于 2018-01-01 17:44 +08:00 . Fix a lot of details.
package rest
import (
"fmt"
"strconv"
)
//把一个大小转变成方便读的格式
//human readable file size
func HumanFileSize(bytes int64) string {
var thresh int64 = 1024
if bytes < 0 {
bytes = 0
}
if bytes < thresh {
return fmt.Sprintf("%dB", bytes)
}
var units = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
var u = 0
var tmp = float64(bytes)
var standard = float64(thresh)
for tmp >= standard && u < len(units)-1 {
tmp /= float64(standard)
u++
}
numStr := strconv.FormatFloat(tmp, 'f', 1, 64)
return fmt.Sprintf("%s%s", numStr, units[u])
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/eyebluecn/tank.git
git@gitee.com:eyebluecn/tank.git
eyebluecn
tank
tank
v1.0.5

搜索帮助