0

Operations question

var a = 19, b = 4 b /= a print(b) Result: 0 Why is this 0? Is it because 4/19 is less than a whole number?

4th Jan 2020, 9:37 PM
otto man
otto man - avatar
1 Resposta
+ 3
This is Swift. When both operands are integers, division rounds the result to the nearest integer towards zero. In other words, the result is truncated.
4th Jan 2020, 10:06 PM
Diego
Diego - avatar