I want to convert the a Floating Point Number (0,123456) and round it with b (positive whole number). I use the truncate function to round the Floating point number to a specific length "b"
This is the formula i came up with, however I get an error when compiling with the GHCI
The Function:
calcFloatingNum:: Double -> Int -> Int -> Float
calcFloatingNum a b = truncate ( a * 10^b) /10^b
The Error Code:
* No instance for (Integral Double)
arising from a use of `truncate'
* In the first argument of `(/)', namely `truncate (a * 10 ^ b)'
In the expression: truncate (a * 10 ^ b) / 10 ^ b
In an equation for `calcFloatingNum':
calcFloatingNum a b = truncate (a * 10 ^ b) / 10 ^ b
|
10 | calcFloatingNum a b = truncate ( a * 10^b) /10^b
And if I try anyway it states:
ghci> calcFloatingNum 0.2345 2
<interactive>:1:1: error:
Variable not in scope: calcFloatingNum :: t0 -> t1 -> t
ghci>
So the Signature might be the problem, however I can't seem to find the solution.
I tried converting the numbers with "fromInteger" and "toInteger", however it resulted in Error codes as well.
Double,Int, andInt, but your definition only listsaandbas arguments. This seems unintentional.Doubleis generally better supported, so I'd suggest changing theFloatin your type signature toDouble.