[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: How do I round off a float to x decimal places

Martin Coxall

10/13/2006 3:38:00 PM

> Hi,
>
> This might be a very naive question but I looked through ruby:Float
> documentation for a method which round off's a float number to x decimal
> places with no luck.
>
> Please share if you know.

It rather depends on which of the 14-or-so regulalrly used rounding
algorithms you need.

Float#round has an inbuilt bias toward zero and is therefore not a
useful unbiased rounding in many circumstances.

Martin

1 Answer

Trans

10/13/2006 3:42:00 PM

0


Martin Coxall wrote:
> > Hi,
> >
> > This might be a very naive question but I looked through ruby:Float
> > documentation for a method which round off's a float number to x decimal
> > places with no luck.
> >
> > Please share if you know.
>
> It rather depends on which of the 14-or-so regulalrly used rounding
> algorithms you need.
>
> Float#round has an inbuilt bias toward zero and is therefore not a
> useful unbiased rounding in many circumstances.
>
> Martin

Chekc out:

http://facets.rubyforge.org/api/core/...

Look for the round_* methods.

T.