[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Fractional part of a float

Jari Williamsson

11/12/2007 11:03:00 PM

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 Williamsson

4 Answers

7stud --

11/12/2007 11:11:00 PM

0

Jari Williamsson 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)
--
Posted via http://www.ruby-....

Wayne Vucenic

11/12/2007 11:22:00 PM

0

> 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


On Nov 12, 2007 3:11 PM, 7stud -- <bbxx789_05ss@yahoo.com> wrote:
> Jari Williamsson 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)
> --
> Posted via http://www.ruby-....
>
>

Lloyd Linklater

11/12/2007 11:23:00 PM

0

7stud -- wrote:
> Jari Williamsson 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?

--
Posted via http://www.ruby-....

Stefan Rusterholz

11/13/2007 12:27:00 AM

0

Wayne Vucenic 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
--
Posted via http://www.ruby-....