🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Rounding off a double precision variable

#4140
From: Ron Natalie
Date: Fri, 25 Feb 2000 00:00
25 lines
1965 bytes

Thomas Krog Christensen wrote:
> 
> "Tomas Alvier" <tal@nfis.no> wrote in message
> news:C5Ns4.5456$kz6.102045@news1.online.no...
> > Is there a function for rounding of a double precision variable to a
> chosen
> > number of decimals?
> 
> double void RoundOff(double x,int noDecimal){
>     int f=x*pow(10,noDecimal);
>     return floor(x*f+0.5)/f;
> }
>
Of course computationally that will do it, but the real question is
what the original poster really wanted.  If he wanted the value only
"DISPLAYED" to a certain number of decimal places, this won't accomplish
it.

---
[ 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: <38B557F1.62342DDE@sensor.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <C5Ns4.5456$kz6.102045@news1.online.no> <8913h0$o97$1@eising.k-net.dk>

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: Ron Natalie <ron@sensor.com>
Subject: Re: Rounding off a double precision variable
Date: 2000/02/25
Message-ID: <38B557F1.62342DDE@sensor.com>
X-Deja-AN: 589510923
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>
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=x-user-defined
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 951432289 mail2news:13864 mail2news mail2news.demon.co.uk
Organization: Sensor Systems
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Mime-Version: 1.0
Newsgroups: comp.std.c++,dk.edb.programmering.c