Confusing DIVISIONS
Be careful
when performing integer division. When dividing an integer
by an integer, the answer will be an integer (not rounded).
Compare these divisions:
(5 is an integer while 5.0
is a double)
Integer division |
8 / 5 = 1 |
Double division |
8.0 / 5.0 = 1.6 |
Mixed division |
8.0 / 5 = 1.6 |
When an operation involves two types (as the
mixed division shown above), the smaller type is converted to the larger type.
In the case above, the integer 5 was converted to a double type
before the division occurred.
|