Skip to content

Maths with numbers

Read · 1 of 6

Whole-number division drops the decimals

+ - * / work as you'd expect, with one big surprise: dividing two ints gives an int, so 17 / 5 is 3, not 3.4.

% gives the remainder: 17 % 5 is 2. It's how you check for even numbers (n % 2 == 0) and pull digits off a number (n % 10 is the last digit).

If either side is a double, you get decimals: 17 / 2.0 is 8.5.