aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/size.go16
-rw-r--r--common/size_test.go4
2 files changed, 10 insertions, 10 deletions
diff --git a/common/size.go b/common/size.go
index bd0fc85c7..6381499a4 100644
--- a/common/size.go
+++ b/common/size.go
@@ -26,10 +26,10 @@ type StorageSize float64
// String implements the stringer interface.
func (s StorageSize) String() string {
- if s > 1000000 {
- return fmt.Sprintf("%.2f mB", s/1000000)
- } else if s > 1000 {
- return fmt.Sprintf("%.2f kB", s/1000)
+ if s > 1048576 {
+ return fmt.Sprintf("%.2f MiB", s/1048576)
+ } else if s > 1024 {
+ return fmt.Sprintf("%.2f KiB", s/1024)
} else {
return fmt.Sprintf("%.2f B", s)
}
@@ -38,10 +38,10 @@ func (s StorageSize) String() string {
// TerminalString implements log.TerminalStringer, formatting a string for console
// output during logging.
func (s StorageSize) TerminalString() string {
- if s > 1000000 {
- return fmt.Sprintf("%.2fmB", s/1000000)
- } else if s > 1000 {
- return fmt.Sprintf("%.2fkB", s/1000)
+ if s > 1048576 {
+ return fmt.Sprintf("%.2fMiB", s/1048576)
+ } else if s > 1024 {
+ return fmt.Sprintf("%.2fKiB", s/1024)
} else {
return fmt.Sprintf("%.2fB", s)
}
diff --git a/common/size_test.go b/common/size_test.go
index f5b6c725e..0938d483c 100644
--- a/common/size_test.go
+++ b/common/size_test.go
@@ -25,8 +25,8 @@ func TestStorageSizeString(t *testing.T) {
size StorageSize
str string
}{
- {2381273, "2.38 mB"},
- {2192, "2.19 kB"},
+ {2381273, "2.27 MiB"},
+ {2192, "2.14 KiB"},
{12, "12.00 B"},
}