Skip to content
instance method

Float#%

(::Integer) -> ::Float
(::Float) -> ::Float
(::Rational) -> ::Float
(::Numeric) -> ::Numeric
self % other → float

Returns self modulo other as a Float.

For float f and real number r, these expressions are equivalent:

Example
f % r
f-r*(f/r).floor
f.divmod(r)[1]

See Numeric#divmod.

Examples:

Example
10.0 % 2              # => 0.0
10.0 % 3              # => 1.0
10.0 % 4              # => 2.0

10.0 % -2             # => 0.0
10.0 % -3             # => -2.0
10.0 % -4             # => -2.0

10.0 % 4.0            # => 2.0
10.0 % Rational(4, 1) # => 2.0
See also #* #** also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0