How to convert number types.

Hi MailList Haskell-Cafe: I am a new haskeller. And was farmilar with C. When tring to do some calculate, like this: input = 5 :: Int factor = 1.20 :: Float output = factor ** (toFloat input) I found that I do not know any function could do just what 'toFloat' should do. What should I do then ? Regards -------------- L.Guo 2008-01-01

"L.Guo"
What should I do then ?
Use fromIntegral. In general, conversion functions are conventionally named fromXXX, and not toXXX, to emphasise functionality somewhat when using them. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited.

2007/12/31, L.Guo
Hi MailList Haskell-Cafe:
I am a new haskeller. And was farmilar with C.
When tring to do some calculate, like this:
input = 5 :: Int factor = 1.20 :: Float output = factor ** (toFloat input)
I found that I do not know any function could do just what 'toFloat' should do.
What should I do then ?
'fromIntegral' do 'toFloat' and others convertions. But in your case, using (^) instead of (**) would probably be the good choice. -- Jedaï

In addition to the other replies, take a look at this wiki page for more conversion advice: http://www.haskell.org/haskellwiki/Converting_numbers Kurt
participants (4)
-
Achim Schneider
-
Chaddaï Fouché
-
Kurt Hutchinson
-
L.Guo