I have this number:
1.89
but I want this part of the number
0.89
is there a way to do that? (Haskell)
I have this number:
1.89
but I want this part of the number
0.89
is there a way to do that? (Haskell)
If the type of the number is an instance of RealFrac, you can make use of properFraction :: (Integral a, RealFrac b) => b -> (a, b) to obtain a 2-tuple with the first item the integral part, and the second the floating part. For example:
Prelude> properFraction 1.89
(1,0.8899999999999999)
You thus can use snd :: (a, b) -> b to obtain the fractional part:
Prelude> snd (properFraction 1.89)
0.8899999999999999
If the number is negative, both the integral part and the fractional part will be negative:
Prelude> properFraction (-1.89)
(-1,-0.8899999999999999)