Ruby built in functions since the kernel module is included by object class its methods are available everywhere in the ruby program.
Ruby method floor.
Floor ndigits integer or float click to toggle source returns the largest number less than or equal to float with a precision of ndigits decimal digits default.
Integer with at least ndigits abs trailing zeros.
Returns self when ndigits is zero or positive.
This also works for while loops.
Floor puts result1 use ceil to move to the next highest integer.
Floor is a float class method which return the floor value of the passed float value.
They can be called without a receiver functional.
In ruby 1 8 the proc method is equivalent to lambda.
When the precision is negative the returned value is an integer with at least ndigits abs trailing zeros.
It is basically equivalent to proc new in ruby 1 9 but not in ruby 1 8.
How to extract a substring a substring is a smaller part of a string it s useful if you only want that specific part like the beginning middle or end.
This will produce the following result.
Ceil puts result2 output 1 1 1 2.
If you re using 1 9 there is a way to find out if you re dealing.
The methods go lower and higher to the next integer.
If it wasn t clear yet ruby is very flexible here s yet another method for creating a loop.
Usr bin ruby num 12 40 puts num floor 12 puts num 10 22 40 puts num integer.
When you use break you ll end the loop immediately so keep that in mind.
For ve precision.
False as num is a float.
Ruby float floor method with example.
Floor ndigits integer or float click to toggle source returns the largest number less than or equal to int with a precision of ndigits decimal digits default.
As you may have guessed there is a difference between procs and lambdas see below so you need to be aware of whether you re using ruby 1 8 or 1 9.
The key here is the ruby break keyword.
When the precision is negative the returned value is an integer with at least ndigits abs trailing zeros.
Smallest number to float with a ndigits decimal point precision.
1 upto 5 i puts i which prints numbers from 1 to 5.