github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/utilities/common/size.go (about) 1 package common 2 3 import ( 4 "fmt" 5 ) 6 7 type StorageSize float64 8 9 func (s StorageSize) String() string { 10 if s > 1000000 { 11 return fmt.Sprintf("%.2f mB", s/1000000) 12 } else if s > 1000 { 13 return fmt.Sprintf("%.2f kB", s/1000) 14 } else { 15 return fmt.Sprintf("%.2f B", s) 16 } 17 } 18 19 func (s StorageSize) TerminalString() string { 20 if s > 1000000 { 21 return fmt.Sprintf("%.2fmB", s/1000000) 22 } else if s > 1000 { 23 return fmt.Sprintf("%.2fkB", s/1000) 24 } else { 25 return fmt.Sprintf("%.2fB", s) 26 } 27 }