add log-system, bug fixed

This commit is contained in:
lzx
2025-11-18 11:10:16 +08:00
parent ac22db02f3
commit 74d9a114c0
13 changed files with 861 additions and 186 deletions

View File

@@ -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 {