Restrict size to 2 fractional digits for docker images

This fix tries to address the issue raised in 26300. Previously
`docker images` will use `HumanSize()` to display the size which
has a fixed precision of 4 (thus 3 fractional digits). This
could be problematic in certain languages (e.g. , German, see
26300) as `.` may be interpreted as thousands-separator in number.

This fix use `CustomSize()` instead and limit the precision to 3
(thus 2 fractional digits).

This fix has been tested manually.

This fix fixes 26300.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2016-09-04 14:44:34 -07:00
parent e2f7387906
commit c68bb57959
5 changed files with 7 additions and 7 deletions

View File

@ -194,8 +194,8 @@ func (s *containerStats) Display(w io.Writer) error {
s.CPUPercentage,
units.BytesSize(s.Memory), units.BytesSize(s.MemoryLimit),
s.MemoryPercentage,
units.HumanSize(s.NetworkRx), units.HumanSize(s.NetworkTx),
units.HumanSize(s.BlockRead), units.HumanSize(s.BlockWrite),
units.HumanSizeWithPrecision(s.NetworkRx, 3), units.HumanSizeWithPrecision(s.NetworkTx, 3),
units.HumanSizeWithPrecision(s.BlockRead, 3), units.HumanSizeWithPrecision(s.BlockWrite, 3),
s.PidsCurrent)
return nil
}

View File

@ -25,7 +25,7 @@ func TestDisplay(t *testing.T) {
t.Fatalf("c.Display() gave error: %s", err)
}
got := b.String()
want := "app\t30.00%\t100 MiB / 2 GiB\t4.88%\t104.9 MB / 838.9 MB\t104.9 MB / 838.9 MB\t1\n"
want := "app\t30.00%\t100 MiB / 2 GiB\t4.88%\t105 MB / 839 MB\t105 MB / 839 MB\t1\n"
if got != want {
t.Fatalf("c.Display() = %q, want %q", got, want)
}