In Ruby, you can use the floor method to round a number down to the nearest integer. Here's an example:
main.rb37 chars3 lines
In this example, x.floor returns the integer 3, which is the largest integer less than or equal to x. If x was negative, floor would round it towards negative infinity.
You can also use floor with a negative argument to round to a specific number of decimal places. For example:
main.rb43 chars3 lines
In this example, x.floor(2) returns the number 3.14, which is the largest number less than or equal to x with two decimal places.
gistlibby LogSnag