mirror of https://github.com/ethereum/go-ethereum
parent
3f904bf3ac
commit
6afc16399f
@ -0,0 +1,15 @@ |
||||
package ethutil |
||||
|
||||
import "fmt" |
||||
|
||||
type StorageSize float64 |
||||
|
||||
func (self StorageSize) String() string { |
||||
if self > 1000000 { |
||||
return fmt.Sprintf("%.2f mB", self/1000000) |
||||
} else if self > 1000 { |
||||
return fmt.Sprintf("%.2f kB", self/1000) |
||||
} else { |
||||
return fmt.Sprintf("%.2f B", self) |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
package ethutil |
||||
|
||||
import ( |
||||
"fmt" |
||||
"testing" |
||||
) |
||||
|
||||
func TestSize(t *testing.T) { |
||||
fmt.Println(StorageSize(2381273)) |
||||
fmt.Println(StorageSize(2192)) |
||||
fmt.Println(StorageSize(12)) |
||||
} |
Loading…
Reference in new issue