Dividing two numbers
suggest changeWhen dividing two numbers, pay attention to the type you want back. Dividing two integers uses integer division. For a float result, at least one operand must be a Float.
Integer division:
3 / 2 # => 1
Float division:
3 / 3.0 # => 1.0
16 / 2 / 2 # => 4
16 / 2 / 2.0 # => 4.0
16 / 2.0 / 2 # => 4.0
16.0 / 2 / 2 # => 4.0
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents