Article View: alt.comp.lang.learn.c-c++
Article #631Re: How to do floating point division?
From: Gerard Krupa
Date: Mon, 22 Feb 1999 00:00
Date: Mon, 22 Feb 1999 00:00
20 lines
1535 bytes
1535 bytes
Jules <julius@clara.net> wrote in message
news:7Riz2.11845$cQ5.6291@nnrp2.clara.net...
>Dear all, I want to do a const line like this in C++:
>
>const float pi = 22/7;
>
>but '/' will only return an int, so how do I have a float to store in pi?
Try const float pi = 22.0 / 7.0.
Of course it would be better to put
const float pi = 3.141592 (since it's *far* more accurate - 22/7 returns
3.142857).
Gerard Krupa
--
The opinions expressed here are also available in hardback.
(Remove the obvious to reply)
Technical Details
Message-ID:
<jWkA2.227$Dy4.72@nnrp2.clara.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7Riz2.11845$cQ5.6291@nnrp2.clara.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 143fed,e29ff327add874ff X-Google-Attributes: gid143fed,public X-Google-Thread: fb1d5,e29ff327add874ff X-Google-Attributes: gidfb1d5,public X-Google-Thread: 109fba,e29ff327add874ff X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,e29ff327add874ff X-Google-Attributes: gid114592,public From: "Gerard Krupa" <krupa.nospamplease@pemail.net> Subject: Re: How to do floating point division? Date: 1999/02/22 Message-ID: <jWkA2.227$Dy4.72@nnrp2.clara.net> X-Deja-AN: 447248282 References: <7Riz2.11845$cQ5.6291@nnrp2.clara.net> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800 X-Complaints-To: abuse@clara.net X-Trace: nnrp2.clara.net 919722767 195.8.90.175 (Mon, 22 Feb 1999 22:32:47 BST) Organization: Marconi Communications X-MSMail-Priority: Normal NNTP-Posting-Date: Mon, 22 Feb 1999 22:32:47 BST Newsgroups: alt.comp.lang.learn.c-c++,claranet.local.help,claranet.local.tech,comp.lang.c++