mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
unpad empty precision from byte formatting
This commit is contained in:
parent
1a615ed9fd
commit
5eda9e4d09
@ -15,11 +15,9 @@ type Docker struct {
|
||||
|
||||
func NewDocker(client *api.Client, id string) *Docker {
|
||||
c := &Docker{
|
||||
Metrics{},
|
||||
make(chan Metrics),
|
||||
make(chan bool),
|
||||
0,
|
||||
0,
|
||||
Metrics: Metrics{},
|
||||
stream: make(chan Metrics),
|
||||
done: make(chan bool),
|
||||
}
|
||||
|
||||
stats := make(chan *api.Stats)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user