delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/15/16:47:28

From: andyl17 AT hotmail DOT com (Andy17)
Newsgroups: comp.os.msdos.djgpp
Subject: Discrepancy in printing a type float
Message-ID: <39204d14.77225094@news-server.socal.rr.com>
X-Newsreader: Forte Free Agent 1.21/32.243
Lines: 22
Date: Mon, 15 May 2000 19:45:21 GMT
NNTP-Posting-Host: 24.24.199.162
X-Complaints-To: abuse AT rr DOT com
X-Trace: typhoon.we.rr.com 958419921 24.24.199.162 (Mon, 15 May 2000 12:45:21 PDT)
NNTP-Posting-Date: Mon, 15 May 2000 12:45:21 PDT
Organization: Road Runner
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I'm using DJGPP/RHIDE and am producing what appears to me a strange
result when printing a float variable. After assigning a value and
calling printf to display the result:

profit = 2150.48;
printf("Profit $%f\n", profit);

it produces:

Profit: $2150.479980

Of course I learned that printf displays a floating point variable
with six digits after the decimal point by default. Why though does it
print out .479980 instead of .480000? I'm guessing that its a setting
within DJGPP/RHIDE that is set at default to produce this output but I
have had no luck finding where to change this. Or is this a C issue
rather than compiler specific? Would appreciate any help shedding some
light on this matter.

Thanks,

Andy

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019