Documentation ¶
Index ¶
- func IsNumber(input any) bool
- func ToAddress(input any) common.Address
- func ToBigInt(input any) *big.Int
- func ToBool(input any) bool
- func ToDecimal(input any) decimal.Decimal
- func ToFloat64(input any) float64
- func ToHash(input any) common_eth.Hash
- func ToInt(input any) int
- func ToInt64(input any) int64
- func ToLowerString(input any) string
- func ToString(input any) string
- func ToUpperString(input any) string
- type AddressTypes
- type BigNumber
- type Float
- type Integer
- type Number
- type Ordered
- type OrderedNumber
- type Signed
- type Unsigned
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToAddress ¶
Convert string into go-ethereum address.
Input must be go-ethereum address or length 42 string, otherwise will return 0x0.
Example ¶
fmt.Println(ToAddress(1)) fmt.Println(ToAddress("111")) fmt.Println(ToAddress("0xdAC17F958D2ee523a2206206994597C13D831ec7")) fmt.Println(ToAddress("0xdac17f958d2ee523a2206206994597c13d831ec7"))
Output: 0x0000000000000000000000000000000000000000 0x0000000000000000000000000000000000000000 0xdAC17F958D2ee523a2206206994597C13D831ec7 0xdAC17F958D2ee523a2206206994597C13D831ec7
func ToBigInt ¶
Convert number or string into *big.Int.
Input must be number or number string, otherwise will return 0.
Example ¶
fmt.Println(ToBigInt(1)) fmt.Println(ToBigInt(1.4)) fmt.Println(ToBigInt(1.8)) fmt.Println(ToBigInt("2")) fmt.Println(ToBigInt("2.3"))
Output: 1 1 2 2 <nil>
func ToDecimal ¶
Convert number or string into decimal.Decimal.
Input must be number or number string, otherwise will return 0.
Example ¶
fmt.Println(ToDecimal(big.NewInt(9))) fmt.Println(ToDecimal(9.9)) fmt.Println(ToDecimal("9.99"))
Output: 9 9.9 9.99
func ToFloat64 ¶
Convert number or string into float64.
Input must be number or number string, otherwise will return 0.
Example ¶
fmt.Println(ToFloat64(1)) fmt.Println(ToFloat64(1.4)) fmt.Println(big.NewFloat(1.8))
Output: 1 1.4 1.8
func ToInt64 ¶
Convert number, string or bool value into int64.
Input must be number, number string or bool value, otherwise will return 0.
Float number will return the round int.
Can convert strings start by 0x, 0o or 0b to Dec int.
True ==> 1; False ==> 0.
Example ¶
fmt.Println(ToInt64(1.4)) fmt.Println(ToInt64(1.8)) fmt.Println(ToInt64(big.NewInt(2))) fmt.Println(ToInt64(big.NewFloat(2.6))) fmt.Println(ToInt64("0x11")) fmt.Println(ToInt64("0o66")) fmt.Println(ToInt64(true))
Output: 1 2 2 3 17 54 1
func ToLowerString ¶
func ToString ¶
Convert anything to string.
Example ¶
fmt.Println(ToString(1)) fmt.Println(ToString(1.1)) fmt.Println(ToString(true))
Output: 1 1.1 true
func ToUpperString ¶
Types ¶
type AddressTypes ¶
type OrderedNumber ¶
Number types that can use <, >, etc.