mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
common: improve functions of StorageSize (#19244)
This commit is contained in:
parent
66921899e9
commit
a747a9861d
1 changed files with 10 additions and 2 deletions
|
|
@ -26,7 +26,11 @@ type StorageSize float64
|
|||
|
||||
// String implements the stringer interface.
|
||||
func (s StorageSize) String() string {
|
||||
if s > 1048576 {
|
||||
if s > 1099511627776 {
|
||||
return fmt.Sprintf("%.2f TiB", s/1099511627776)
|
||||
} else if s > 1073741824 {
|
||||
return fmt.Sprintf("%.2f GiB", s/1073741824)
|
||||
} else if s > 1048576 {
|
||||
return fmt.Sprintf("%.2f MiB", s/1048576)
|
||||
} else if s > 1024 {
|
||||
return fmt.Sprintf("%.2f KiB", s/1024)
|
||||
|
|
@ -38,7 +42,11 @@ func (s StorageSize) String() string {
|
|||
// TerminalString implements log.TerminalStringer, formatting a string for console
|
||||
// output during logging.
|
||||
func (s StorageSize) TerminalString() string {
|
||||
if s > 1048576 {
|
||||
if s > 1099511627776 {
|
||||
return fmt.Sprintf("%.2fTiB", s/1099511627776)
|
||||
} else if s > 1073741824 {
|
||||
return fmt.Sprintf("%.2fGiB", s/1073741824)
|
||||
} else if s > 1048576 {
|
||||
return fmt.Sprintf("%.2fMiB", s/1048576)
|
||||
} else if s > 1024 {
|
||||
return fmt.Sprintf("%.2fKiB", s/1024)
|
||||
|
|
|
|||
Loading…
Reference in a new issue