The modulo operator (%) returns the remainder of integer division of two numbers. It is very common to use when you want to know if a number is even or odd.
# 6% 2 == 0
# 5% 2 == 1
All that follows the # sign is a comment, 6% 2 returns 0 , 6 is even number. Otherwise, 5, the remainder is 1.
Operator Division:
5 / 2 # == 2
This is because when you divide two integers the result is an integer, to get the real value, at least one operand must be floating
5 / 2.0 # == 2.5
integer division operator:
5 / / 2 # == 2
5 / / 2.0 == 2.0 #
5 / / 3.33 # == 1.0
This operator does not show decimals, nothing but the whole.
0 comments:
Post a Comment