div(other) -> IntegerRuby 2.4.0 から[permalink][rdoc][edit]-
整商(整数の商)を返します。普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
otherがIntegerオブジェクトの場合、Integer#/ の結果と一致します。divに対応する剰余メソッドはmoduloです。- [PARAM]
other: - 二項演算の右側の引数(対象)
- [RETURN]
- 計算結果
p 7.div(2) # => 3 p 7.div(-2) # => -4 p 7.div(2.0) # => 3 p 7.div(2r) # => 3 begin 2.div(0) rescue => e e # => #<ZeroDivisionError: divided by 0> end begin 2.div(0.0) rescue => e e # => #<ZeroDivisionError: divided by 0> # Integer#/ と違い、引数が Float でもゼロで割ることはできない end[SEE_ALSO] Integer#fdiv, Integer#/, Integer#modulo
- [PARAM]