GoLang 文件大小显示优化
GoLang 文件大小显示优化(简易版)
GoLang 文件大小显示优化(简易版)
func getFriendlyFileSize(fileSize
int64) (size
string) {
if fileSize
< 1024 {
return fmt
.Sprintf("%.2fB", float64(fileSize
)/float64(1))
} else if fileSize
< (1024 * 1024) {
return fmt
.Sprintf("%.2fKB", float64(fileSize
)/float64(1024))
} else if fileSize
< (1024 * 1024 * 1024) {
return fmt
.Sprintf("%.2fMB", float64(fileSize
)/float64(1024*1024))
} else if fileSize
< (1024 * 1024 * 1024 * 1024) {
return fmt
.Sprintf("%.2fGB", float64(fileSize
)/float64(1024*1024*1024))
} else if fileSize
< (1024 * 1024 * 1024 * 1024 * 1024) {
return fmt
.Sprintf("%.2fTB", float64(fileSize
)/float64(1024*1024*1024*1024))
} else {
return fmt
.Sprintf("%.2fEB", float64(fileSize
)/float64(1024*1024*1024*1024*1024))
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-44851.html