[Haskell-cafe] round function

Chatzianastassiou Achilleas achatzianastassiou at hotmail.com
Sun Feb 12 17:45:47 EST 2006


In addition to my previous quote, I don't understand the user of
fromIntegral
At the prelude, when i type i.e. fromIntegral 4 it returns 4
Thanks

>From: Sebastian Sylvan <sebastian.sylvan at gmail.com>
>Reply-To: sylvan at student.chalmers.se
>To: Chatzianastassiou Achilleas <achatzianastassiou at hotmail.com>
>CC: haskell-cafe at haskell.org
>Subject: Re: [Haskell-cafe] round function
>Date: Sun, 12 Feb 2006 22:23:17 +0100
>
>On 2/12/06, Chatzianastassiou Achilleas <achatzianastassiou at hotmail.com> 
>wrote:
> > Hi all,
> >
> > I am trying to implement a function that finds the significant figure of 
>a
> > number to a specified point i.e. 2.55555 3 = 2.556. I have implemented
> > something like:
> >
> > sig :: (RealFrac a, Integral b) => a -> Int -> a
> > sig x y = round y
> >
> > However this doesn't work. Moreover at the Prelude when i type round 
>2.3333
> > 2 i get an error.
> > Any suggestions?
> >
>
>Something like:
>
>myround n s = fromIntegral (round (n * factor)) / factor
>     where factor = fromIntegral (10^s)
>
>Basically scaling it to bring the specified number of digits to the
>left of the decimal point, then rounding, then scaling back.
>
>/S
>
>--
>Sebastian Sylvan
>+46(0)736-818655
>UIN: 44640862

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to 
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement



More information about the Haskell-Cafe mailing list