還記得中小學教的加減乘除嗎 ? 這些算符就是那樣用的。
表格 10-1.算術運算符
示範 | 算符名稱 | 運算結果 |
---|---|---|
$a + $b | 加法 Addition | $a 、$b 的和 |
$a - $b | 減法 Subtraction | $a、 $b 的差 |
$a * $b | 乘法 Multiplication | $a 、$b 的積 |
$a / $b | 除法 Division | $a 、$b 的商 |
$a % $b | 餘數 Modulus | $a 除以 $b 後的餘數 |
The division operator ("/") returns an integer value (the result of an integer division) if the two operands are integers (or strings that get converted to integers) and the quotient is an integer. If either operand is a floating-point value, or the operation results in a non-integer value, a floating-point value is returned.