add byte formatting for tb

This commit is contained in:
Bradley Cicenas
2017-06-09 14:14:27 -03:00
parent fb39d69fa7
commit c1780ae30a

View File

@@ -9,6 +9,7 @@ const (
kb = 1024 kb = 1024
mb = kb * 1024 mb = kb * 1024
gb = mb * 1024 gb = mb * 1024
tb = gb * 1024
) )
// convenience method // convenience method
@@ -28,8 +29,12 @@ func ByteFormat(n int64) string {
n = n / mb n = n / mb
return fmt.Sprintf("%sM", strconv.FormatInt(n, 10)) return fmt.Sprintf("%sM", strconv.FormatInt(n, 10))
} }
nf := float64(n) / gb if n < tb {
return fmt.Sprintf("%sG", unpadFloat(nf)) nf := float64(n) / gb
return fmt.Sprintf("%sG", unpadFloat(nf))
}
nf := float64(n) / tb
return fmt.Sprintf("%sT", unpadFloat(nf))
} }
func unpadFloat(f float64) string { func unpadFloat(f float64) string {