unpad empty precision from byte formatting

This commit is contained in:
Bradley Cicenas
2017-01-20 15:56:49 +00:00
parent 1a615ed9fd
commit 5eda9e4d09
2 changed files with 20 additions and 7 deletions

View File

@@ -30,8 +30,23 @@ func byteFormat(n int64) string {
n = n / mb
return fmt.Sprintf("%sM", strconv.FormatInt(n, 10))
}
n = n / gb
return fmt.Sprintf("%sG", strconv.FormatInt(n, 10))
nf := float64(n) / gb
return fmt.Sprintf("%sG", unpadFloat(nf))
}
func unpadFloat(f float64) string {
return strconv.FormatFloat(f, 'f', getPrecision(f), 64)
}
func getPrecision(f float64) int {
frac := int((f - float64(int(f))) * 100)
if frac == 0 {
return 0
}
if frac%10 == 0 {
return 1
}
return 2 // default precision
}
func colorScale(n int) ui.Attribute {