From c1780ae30a8955672819c428f7a6a86c82e70122 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Fri, 9 Jun 2017 14:14:27 -0300 Subject: [PATCH] add byte formatting for tb --- cwidgets/util.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cwidgets/util.go b/cwidgets/util.go index ba6c326..4fa1243 100644 --- a/cwidgets/util.go +++ b/cwidgets/util.go @@ -9,6 +9,7 @@ const ( kb = 1024 mb = kb * 1024 gb = mb * 1024 + tb = gb * 1024 ) // convenience method @@ -28,8 +29,12 @@ func ByteFormat(n int64) string { n = n / mb return fmt.Sprintf("%sM", strconv.FormatInt(n, 10)) } - nf := float64(n) / gb - return fmt.Sprintf("%sG", unpadFloat(nf)) + if n < tb { + nf := float64(n) / gb + return fmt.Sprintf("%sG", unpadFloat(nf)) + } + nf := float64(n) / tb + return fmt.Sprintf("%sT", unpadFloat(nf)) } func unpadFloat(f float64) string {