Numbers & Money in Cents

Int arithmetic

Ints support the arithmetic you expect: +, -, (multiply), / (divide). 1500 2 is 3000, 1500 + 500 is 2000.

Division has a twist worth burning into memory: when both sides are Ints, the result is an Int β€” the remainder is thrown away. 7 / 2 is 3, not 3.5. There's no rounding: 2599 / 100 is 25, even though 25.99 is "closer" to 26. This is called truncation.

Truncation sounds like a bug waiting to happen. Used deliberately, it's a tool β€” and PawWalk uses it on purpose, as you're about to see.