From 9316bf3f9f1e6ada1bb993bacf500d85db76fcfe Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 2 Apr 2024 20:34:07 +0200 Subject: [PATCH] common: simplify floatToEth --- common/common.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/common/common.go b/common/common.go index c8c0a914..1af8e4fa 100644 --- a/common/common.go +++ b/common/common.go @@ -41,17 +41,14 @@ func GetEnvFloat64(key string, defaultValue float64) float64 { // FloatEthTo256Wei converts a float (precision 10) denominated in eth to a U256Str denominated in wei func FloatEthTo256Wei(val float64) (*types.U256Str, error) { - weiU256 := new(types.U256Str) - ethFloat := new(big.Float) weiFloat := new(big.Float) weiFloatLessPrecise := new(big.Float) - weiInt := new(big.Int) - ethFloat.SetFloat64(val) - weiFloat.Mul(ethFloat, big.NewFloat(1e18)) + weiFloat.Mul(new(big.Float).SetFloat64(val), big.NewFloat(1e18)) weiFloatLessPrecise.SetString(weiFloat.String()) - weiFloatLessPrecise.Int(weiInt) + weiInt, _ := weiFloatLessPrecise.Int(nil) + weiU256 := new(types.U256Str) err := weiU256.FromBig(weiInt) return weiU256, err }