Rounding Numbers

suggest change

round rounds a positive number up when the first dropped digit is 5 or more, and down when it is 4 or less. An optional argument sets how many digits to keep after the decimal point.

4.89.round        # => 5
4.25.round        # => 4
3.141526.round(1) # => 3.1
3.141526.round(2) # => 3.14
3.141526.round(4) # => 3.1415

floor returns the greatest integer less than or equal to the number.

4.9999999999999.floor # => 4

ceil returns the least integer greater than or equal to the number.

4.0000000000001.ceil  # => 5

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents