🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.commandlinetools
Article #321

Re: Precision of Real Types

#321
From: Mike Williams [TeamB]
Date: Tue, 23 Nov 2004 15:18
25 lines
1855 bytes
On 23 Nov 2004, "Marcos" <praia.rio@ig.com.br> wrote:

> How set the precision of Real Types ?
> Exemple:
> 1,23456534345 to 1,2345

I'm not sure what this has to do with command line tools but you can't 
change the internal precision of a floating point type.  What you 
normally do is format it to however many places you like whenever 
displaying it as a string.  While you can round a floating point type to 
a specific number of decimal places and store it back in the variable you 
have to be aware of the inaccuracies of storing decimal values in a 
binary format.  To round a number to 3 places:

procedure TForm1.Button1Click(Sender: TObject);
var x : Double;
begin
  x := 1.23456789;
  x := round(x * 1000) / 1000;
  Caption := Format('%10.10f', [x]); // 1.2350000000
end;

-- 
-Mike (TeamB)
Newsgroup guidelines: http://www.borland.com/newsgroups/guide.html
Technical Details
Message-ID: <Xns95AA730BC6F4mikewteamb@207.105.83.66>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41a355eb$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: ff8f1,e23868ee33689e70
X-Google-Attributes: gidff8f1,public
X-Google-Language: ENGLISH,ASCII-7-bit
Newsgroups: borland.public.delphi.commandlinetools
Subject: Re: Precision of Real Types
From: "Mike Williams [TeamB]" <mlwilliams@gmail.com>
References: <41a355eb$1@newsgroups.borland.com>
Organization: APS, Inc
Message-ID: <Xns95AA730BC6F4mikewteamb@207.105.83.66>
User-Agent: Xnews/06.08.25
X-Face: ":yn4zt^A_dn>6~{YJmu^B\'4w)e:apPM\VC=Dvf&*tASxX9|BYczkFd$xr.$vNSZ[3Uobr p]c4\+\l){!WQI.$]veP({HLd;CDYH?iN
NNTP-Posting-Host: 66.107.65.116
Date: 23 Nov 2004 08:18:33 -0700
X-Trace: newsgroups.borland.com 1101226713 66.107.65.116 (23 Nov 2004 08:18:33 -0700)
Lines: 26
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail