Converting Integer to Double in Haskell

The usual way to convert an Int to a Double is to use fromIntegral, which has the type (Integral a, Num b) => a -> b. This means that it converts an Integral type (Int and Integer) to any numeric type b, of which Double is an instance.

Your case sounds like you want to convert a Double to an Int, which I would recommend floor for, but you’ll have to make sure that your input is a Double. For this, you can use the fromIntegral function with

take 52 $ iterate (floor . (* 1.1) . fromIntegral) 100

However, this will give you inaccurate results, since you are truncating at each step. I would suggest doing

take 52 $ map floor $ iterate (* 1.1) $ fromIntegral 100

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)