Files
m2pool_payment/internal/utils/utils.go
2025-10-16 18:54:27 +08:00

41 lines
966 B
Go

package utils
import (
"log"
"math"
"math/big"
)
func BigIntUSDTToFloat64(value *big.Int) float64 {
f := new(big.Float).SetInt(value)
scale := new(big.Float).SetFloat64(1e6) // USDT 精度 6 位
f.Quo(f, scale)
result, _ := f.Float64()
return result
}
// USDT 一般精度是 6 位小数
const USDTDecimals = 6
// Float64ToBigIntUSDT 将 float64 金额转换成 *big.Int
func Float64ToBigIntUSDT(amount float64) *big.Int {
// 乘上精度系数
scale := math.Pow10(USDTDecimals)
bigAmount := new(big.Int)
bigAmount.SetInt64(int64(amount * scale))
return bigAmount
}
func Slice_delete(arr []any, index int) []any {
if index < 0 || index >= len(arr) {
// 处理越界
log.Fatalf("slice arr error: index=%d, arr length=%d", index, len(arr))
return nil
}
if index >= 0 && index < len(arr) {
copy(arr[index:], arr[index+1:]) // 后面的元素往前移动
arr = arr[:len(arr)-1] // 去掉最后一个多余元素
}
return arr
}