slideshow/internal/formatter.go

18 lines
341 B
Go

package internal
import "strconv"
// format bytes
func FormatBytes(bytes int64) string {
value := float64(bytes)
unit := "bytes"
if bytes > 1000000 {
value = value / 1000000
unit = "mega" + unit
} else if bytes > 1000 {
value = value / 1000
unit = "kilo" + unit
}
return strconv.FormatFloat(value, 'f', 2, 64) + " " + unit
}