package str import ( "fmt" ) // FormatBytes 格式化bytes func FormatBytes(size float64) string { units := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} i := 0 for ; size >= 1024 && i < len(units); i++ { size /= 1024 } return fmt.Sprintf("%.2f %s", size, units[i]) }