round Rounds to the nearest integer. : float « Number « Ruby
- Ruby
- Number
- float
round Rounds to the nearest integer.
def round
case
when self > 0.0 then (self+0.5).floor
when self < 0.0 then return (self?.5).ceil
else 0
end
end
1.5.round
(3.5).round
Related examples in the same category