add log-system, bug fixed
This commit is contained in:
@@ -78,9 +78,24 @@ func Float64ToBigInt(symbol string, amount float64) *big.Int {
|
||||
log.Printf("don`t support symbol: %s", symbol)
|
||||
return nil
|
||||
}
|
||||
bigAmount := new(big.Int)
|
||||
bigAmount.SetInt64(int64(amount * scale))
|
||||
return bigAmount
|
||||
|
||||
// 检查 amount 是否为负数
|
||||
if amount < 0 {
|
||||
log.Printf("Warning: negative amount for symbol %s: %f", symbol, amount)
|
||||
amount = 0 // 可以选择将负数设置为 0 或返回错误
|
||||
}
|
||||
|
||||
// 将 amount 转换为 big.Float 来避免溢出
|
||||
bigAmount := new(big.Float)
|
||||
bigAmount.SetFloat64(amount)
|
||||
|
||||
// 乘以 scale(小数位数),避免精度丢失
|
||||
bigAmount = bigAmount.Mul(bigAmount, big.NewFloat(scale))
|
||||
|
||||
// 将 big.Float 转换为 big.Int(取整)
|
||||
intAmount, _ := bigAmount.Int(nil)
|
||||
|
||||
return intAmount
|
||||
}
|
||||
|
||||
func BigIntToFloat64(symbol string, amount *big.Int) float64 {
|
||||
|
||||
Reference in New Issue
Block a user