Skip to content

Commit

Permalink
🐛 Avoid crashing because of a division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
micheartin committed Oct 27, 2022
1 parent b621be0 commit c0b7635
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/rainbow/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ func ToFloat(n *big.Int, decimals int64) float64 {
if decimals == 0 {
return float64(n.Int64())
}

// divide by 10^(decimals-5)
divisor := big.NewInt(int64(math.Pow(10, float64(decimals-5))))
if divisor.Int64() == 0 {
return 0
}

q := big.NewInt(0)
q.Quo(n, big.NewInt(int64(math.Pow(10, float64(decimals-5))))) // divided by 10^(decimals-5)
q.Quo(n, divisor)
return float64(q.Int64()) / 100000.0
}

Expand Down

0 comments on commit c0b7635

Please sign in to comment.