[Haskell-cafe] Converting from Int to Double

Jorge Adriano Aires jadrian at mat.uc.pt
Wed Jan 26 16:09:17 EST 2005


> >> How can I convert an Int into a Double?
> >
> > You don't convert to, you convert from :-)
> > The function 'fromIntegral' is probably what you want.
>
> And what function can I use to convert from Double to Int (the inverse of
> fromIntegral) ?

Use the functions in the RealFrac class.
http://www.haskell.org/onlinereport/standard-prelude.html#$tRealFrac

class  (Real a, Fractional a) => RealFrac a  where
     properFraction   :: (Integral b) => a -> (b,a)
     truncate, round  :: (Integral b) => a -> b
     ceiling, floor   :: (Integral b) => a -> b

J.A.



More information about the Haskell-Cafe mailing list