
Hi, I have a complex double (x :+ y) where 'x' and 'y' are computed using sin and cos functions on an angle expressed in radians. However, the output on the command line (using GHCi) shows up with a lot of decimal places. How can I limit the values of 'x' and 'y' to having only two decimal places? Thanks, Raghav

Because there is already a Show instance for Complex a, you will have to
use your own show function. Something list this.
import Text.Printf
import Data.Complex
showComplex :: Complex Float -> String
showComplex (a :+ b) = (printf "%.2f" a) ++ " :+ " ++ (printf "%.2f" b)
On Tue, Mar 27, 2018 at 12:11 PM, Raghav Malik
Hi,
I have a complex double (x :+ y) where 'x' and 'y' are computed using sin and cos functions on an angle expressed in radians.
However, the output on the command line (using GHCi) shows up with a lot of decimal places. How can I limit the values of 'x' and 'y' to having only two decimal places?
Thanks, Raghav
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Or you could use Centi instead of Float: http://hackage.haskell.org/package/base-4.11.0.0/docs/Data-Fixed.html
participants (3)
-
David McBride
-
Imants Cekusins
-
Raghav Malik