Lesson 4 of 16
Numbers
Arithmetic
Elixir supports standard arithmetic operators:
IO.puts(10 + 3) # 13
IO.puts(10 - 3) # 7
IO.puts(10 * 3) # 30
Integer Division and Remainder
Use div/2 for integer division and rem/2 for remainder:
IO.puts(div(10, 3)) # 3
IO.puts(rem(10, 3)) # 1
Floats
Use Float.round/2 to round to a given number of decimal places:
IO.puts(Float.round(3.14159, 2)) # 3.14
Your Turn
Print:
10 + 3= 1310 - 3= 710 * 3= 30div(10, 3)= 3rem(10, 3)= 1Float.round(3.14159, 2)= 3.14
JS Transpiler loading...
Loading...
Click "Run" to execute your code.