Int to float haskell

In this article let’s discuss about Int to float haskell. Let’s go through the following methods without any delay 🙂

Method 1:

-- Int to Float
-- Useing (/) 
	(/) :: Fractional a => a -> a -> a

{- The following code works: -}

 	percent :: Int -> Int -> Float 
	percent x y =   100 * ( a / b )
      where a = fromIntegral x :: Float
            b = fromIntegral y :: Float

Method 2 :

-- Float to Int
toInt :: Float -> Int
toInt x = round x

Hope the above methods works for you. Happy Learning and get back to us Anytime.

Realted Posts : String to list haskell