Fractional part of a float

Is there any built-in method to get the fractional part from a float, or
do I need to resolve to a…
f - f.to_i
…kind of approach?

Best regards,

Jari W.

Jari W. wrote:

Is there any built-in method to get the fractional part from a float, or
do I need to resolve to a…
f - f.to_i
…kind of approach?

If you think it’s clearer:

8.2675.modulo(1)

7stud – wrote:

Jari W. wrote:

Is there any built-in method to get the fractional part from a float, or
do I need to resolve to a…
f - f.to_i
…kind of approach?

If you think it’s clearer:

8.2675.modulo(1)

It sounds as if we need a new method for numbers, mantissa, where the
fraction portion is returned. Can we add that to the core?

Wayne V. wrote:

8.2675.modulo(1)

irb(main):015:0> -1.2.modulo(1)
=> 0.8

which may or may not be the result the OP wanted.

Wayne

-1.2.abs.modulo(1) # => 0.2

Not all that difficult to avoid if it is not what the OP wanted.

Regards
Stefan

8.2675.modulo(1)

irb(main):015:0> -1.2.modulo(1)
=> 0.8

which may or may not be the result the OP wanted.

Wayne