Skip to content

Commit bee9369

Browse files
committed
memory/size: Base10Size has 2 signs after dot
https://storjlabs.atlassian.net/browse/SG-398 https://storjlabs.atlassian.net/browse/SG-354 Change-Id: I70e5893f4fbb7f1afd2863321596732f34cb9700
1 parent 4c1ddac commit bee9369

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

memory/size.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ func (size Size) Base10String() string {
131131

132132
switch {
133133
case abs(size) >= EB*2/3:
134-
return fmt.Sprintf("%.1f EB", size.EB())
134+
return fmt.Sprintf("%.2f EB", size.EB())
135135
case abs(size) >= PB*2/3:
136-
return fmt.Sprintf("%.1f PB", size.PB())
136+
return fmt.Sprintf("%.2f PB", size.PB())
137137
case abs(size) >= TB*2/3:
138-
return fmt.Sprintf("%.1f TB", size.TB())
138+
return fmt.Sprintf("%.2f TB", size.TB())
139139
case abs(size) >= GB*2/3:
140-
return fmt.Sprintf("%.1f GB", size.GB())
140+
return fmt.Sprintf("%.2f GB", size.GB())
141141
case abs(size) >= MB*2/3:
142-
return fmt.Sprintf("%.1f MB", size.MB())
142+
return fmt.Sprintf("%.2f MB", size.MB())
143143
case abs(size) >= KB*2/3:
144-
return fmt.Sprintf("%.1f KB", size.KB())
144+
return fmt.Sprintf("%.2f KB", size.KB())
145145
}
146146

147147
return strconv.FormatInt(size.Int64(), 10) + " B"

memory/size_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ func TestBase10Size(t *testing.T) {
8080
text string
8181
}{
8282
// basics
83-
{1 * pb, "1.0 PB"},
84-
{1 * eb, "1.0 EB"},
85-
{1 * tb, "1.0 TB"},
86-
{1 * gb, "1.0 GB"},
87-
{1 * mb, "1.0 MB"},
88-
{1 * kb, "1.0 KB"},
83+
{1 * pb, "1.00 PB"},
84+
{1 * eb, "1.00 EB"},
85+
{1 * tb, "1.00 TB"},
86+
{1 * gb, "1.00 GB"},
87+
{1 * mb, "1.00 MB"},
88+
{1 * kb, "1.00 KB"},
8989
{1, "1 B"},
9090
// complicated
91-
{68 * tb, "68.0 TB"},
92-
{256 * mb, "256.0 MB"},
91+
{68 * tb, "68.00 TB"},
92+
{256 * mb, "256.00 MB"},
9393
{500, "500 B"},
9494
{5, "5 B"},
9595
{1, "1 B"},

0 commit comments

Comments
 (0)