Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Rounding to 2 decimal places (Raghav Malik)
2. Re: Rounding to 2 decimal places (David McBride)
3. Re: Rounding to 2 decimal places (Imants Cekusins)
----------------------------------------------------------------------
Message: 1
Date: Tue, 27 Mar 2018 16:11:51 +0000
From: Raghav Malik <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Rounding to 2 decimal places
Message-ID:
<CANGM-H4wE=jtSuO=pxkmkzzmhyvj_x7dgb+h2o1sbh-iedq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180327/bf4b1bd1/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 27 Mar 2018 12:32:56 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Rounding to 2 decimal places
Message-ID:
<can+tr40rxl85fseslmggbd1hafwx9ztekppwn_3_npr0y75...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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 <[email protected]>
wrote:
> 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
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180327/b3b2983b/attachment-0001.html>
------------------------------
Message: 3
Date: Tue, 27 Mar 2018 16:42:26 +0000
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Rounding to 2 decimal places
Message-ID:
<cap1qiny2r2bbgn9ai1utnbbtv7exvb2xu3z8we7a+gswapw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Or you could use Centi instead of Float:
http://hackage.haskell.org/package/base-4.11.0.0/docs/Data-Fixed.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180327/7e91787e/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 117, Issue 15
******************************************