1 // Copyright 2014 The go-ethereum Authors
2 // This file is part of the go-ethereum library.
4 // The go-ethereum library is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // The go-ethereum library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
24 type StorageSize float64
26 func (self StorageSize) String() string {
28 return fmt.Sprintf("%.2f mB", self/1000000)
29 } else if self > 1000 {
30 return fmt.Sprintf("%.2f kB", self/1000)
32 return fmt.Sprintf("%.2f B", self)
36 func (self StorageSize) Int64() int64 {
40 // The different number of units
42 Douglas = BigPow(10, 42)
43 Einstein = BigPow(10, 21)
44 Ether = BigPow(10, 18)
45 Finney = BigPow(10, 15)
46 Szabo = BigPow(10, 12)
47 Shannon = BigPow(10, 9)
48 Babbage = BigPow(10, 6)
55 // Returns a string representing a human readable format
56 func CurrencyToString(num *big.Int) string {
63 case num.Cmp(Ether) >= 0:
64 fin = new(big.Int).Div(num, Ether)
66 case num.Cmp(Finney) >= 0:
67 fin = new(big.Int).Div(num, Finney)
69 case num.Cmp(Szabo) >= 0:
70 fin = new(big.Int).Div(num, Szabo)
72 case num.Cmp(Shannon) >= 0:
73 fin = new(big.Int).Div(num, Shannon)
75 case num.Cmp(Babbage) >= 0:
76 fin = new(big.Int).Div(num, Babbage)
78 case num.Cmp(Ada) >= 0:
79 fin = new(big.Int).Div(num, Ada)
83 // TODO add comment clarifying expected behavior
84 if len(fin.String()) > 5 {
85 return fmt.Sprintf("%sE%d %s", fin.String()[0:5], len(fin.String())-5, denom)
88 return fmt.Sprintf("%v %s", fin, denom)