🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #4136

Re: Rounding off a double precision variable

#4136
From: Kaspar Daugaard
Date: Fri, 24 Mar 2000 00:00
23 lines
1925 bytes
Paul Meyerholtz wrote:
> A question about the function floor() from a newbie.  If I'm trying to
> round off doubles the following seems to work:
> 
> double x;
> ....   x assigned some number ....
> int rounded = int(x +.5);
> 
> Is this compiler dependent?  Don't C++ programs truncate when converting
> from double to int?


You should note that using floor() is different from truncating when the
value is negative, e.g. floor(-2.4) is -3 while int(-2.4) is -2.

- Kaspar

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]
Technical Details
Message-ID: <38DA2D21.12EA4193@SPAMFREEcabocomm.dk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <C5Ns4.5456$kz6.102045@news1.online.no> <8913h0$o97$1@eising.k-net.dk> <38D776C8.6DF0D493@ix.netcom.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109d22,e2bc0eb4b79bfbd0
X-Google-Attributes: gid109d22,public
X-Google-Thread: f78e5,e2bc0eb4b79bfbd0
X-Google-Attributes: gidf78e5,public
From: Kaspar Daugaard <kaspard@SPAMFREEcabocomm.dk>
Subject: Re: Rounding off a double precision variable
Date: 2000/03/24
Message-ID: <38DA2D21.12EA4193@SPAMFREEcabocomm.dk>
X-Deja-AN: 601469481
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <C5Ns4.5456$kz6.102045@news1.online.no> <8913h0$o97$1@eising.k-net.dk> <38D776C8.6DF0D493@ix.netcom.com>
X-Accept-Language: en
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 953847490 mail2news:26362 mail2news mail2news.demon.co.uk
Organization: CABO communications
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Mime-Version: 1.0
Newsgroups: comp.std.c++,dk.edb.programmering.c