How can I calculate a number with an exponent in Elixir?
For example, 23 would return 8.
When you "raise a number to a power," you're multiplying the number by itself, and the "power" represents how many times you do so. So 2 raised to the 3rd power is the same as 2 x 2 x 2, which equals 8.
:math.pow(2,3) #=> 8.0
If you want an integer:
:math.pow(2,3) |> round #=> 8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With