Skip to content

Float functions

abs

Returns the absolute (non-negative) value of the floating point.

<%= -5.0.abs %>
5.0

to_string

Converts the floating point to a string. to_s is an alias for to_string.

<%= 5.2.to_string + " times" %>
5.2 times

to_integer

Converts the floating point to an integer, rounding it. to_i is an alias for to_integer.

<%= 5.2.to_integer * 5 %>
25

round

Rounds the floating point to the nearest whole value.

<%= 5.6.round %>
6.0

ceil

Rounds the float to the upper whole value.

<%= 5.2.ceil %>
6.0

floor

Rounds the float to the lower whole value.

<%= 5.9.ceil %>
5.0