Skip to content

Commit

Permalink
common: simplify floatToEth (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden authored Apr 4, 2024
1 parent 8b662e0 commit 643b8c6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 643b8c6

Please sign in to comment.