forked from tslocum/twins
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
307 B
17 lines
307 B
package main |
|
|
|
import "fmt" |
|
|
|
func formatFileSize(b int64) string { |
|
const unit = 1000 |
|
if b < unit { |
|
return fmt.Sprintf("%d B", b) |
|
} |
|
div, exp := int64(unit), 0 |
|
for n := b / unit; n >= unit; n /= unit { |
|
div *= unit |
|
exp++ |
|
} |
|
return fmt.Sprintf("%.0f %cB", |
|
float64(b)/float64(div), "KMGTPE"[exp]) |
|
}
|
|
|