update
This commit is contained in:
@@ -56,3 +56,46 @@ func Slice_delete(arr []any, index int) []any {
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// 函数:检查一个切片是否包含某个字符串
|
||||
func Contains(slice []string, str string) bool {
|
||||
for _, s := range slice {
|
||||
if s == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func Float64ToBigInt(symbol string, amount float64) *big.Int {
|
||||
var scale float64
|
||||
switch symbol {
|
||||
case "ETH":
|
||||
scale = math.Pow10(ETHDecimals)
|
||||
case "USDT":
|
||||
scale = math.Pow10(USDTDecimals)
|
||||
default:
|
||||
log.Printf("don`t support symbol: %s", symbol)
|
||||
return nil
|
||||
}
|
||||
bigAmount := new(big.Int)
|
||||
bigAmount.SetInt64(int64(amount * scale))
|
||||
return bigAmount
|
||||
}
|
||||
|
||||
func BigIntToFloat64(symbol string, amount *big.Int) float64 {
|
||||
var scale *big.Float
|
||||
f := new(big.Float).SetInt(amount)
|
||||
switch symbol {
|
||||
case "ETH":
|
||||
scale = new(big.Float).SetFloat64(1e18)
|
||||
case "USDT":
|
||||
scale = new(big.Float).SetFloat64(1e6)
|
||||
default:
|
||||
log.Printf("don`t support symbol: %s", symbol)
|
||||
return 0
|
||||
}
|
||||
f.Quo(f, scale)
|
||||
result, _ := f.Float64()
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user