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

@ -15,11 +15,9 @@ type Docker struct {
func NewDocker(client *api.Client, id string) *Docker { func NewDocker(client *api.Client, id string) *Docker {
c := &Docker{ c := &Docker{
Metrics{}, Metrics: Metrics{},
make(chan Metrics), stream: make(chan Metrics),
make(chan bool), done: make(chan bool),
0,
0,
} }
stats := make(chan *api.Stats) stats := make(chan *api.Stats)

View File

@ -30,8 +30,23 @@ 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))
} }
n = n / gb nf := float64(n) / gb
return fmt.Sprintf("%sG", strconv.FormatInt(n, 10)) 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 { func colorScale(n int) ui.Attribute {