delorie.com/archives/browse.cgi | search |
X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
From: | "MarioC" <marioc AT no-spam DOT qitech DOT net> |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | questions about formatting |
Lines: | 25 |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Newsreader: | Microsoft Outlook Express 6.00.2900.2527 |
X-MimeOLE: | Produced By Microsoft MimeOLE V6.00.2900.2527 |
X-RFC2646: | Format=Flowed; Original |
Message-ID: | <knoXd.1026935$35.38170845@news4.tin.it> |
Date: | Tue, 08 Mar 2005 21:00:00 GMT |
NNTP-Posting-Host: | 217.172.194.163 |
X-Complaints-To: | "Please send abuse reports to abuse AT tin DOT it and technical notifications to newsmaster AT tin DOT it" |
X-Trace: | news4.tin.it 1110315600 217.172.194.163 (Tue, 08 Mar 2005 22:00:00 MET) |
NNTP-Posting-Date: | Tue, 08 Mar 2005 22:00:00 MET |
Organization: | TIN |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Hello, I have found something I don't understand with the precision field of the printf() function. The documentation states that, for floating point values, the precision field indicates the maximum number of decimal digits printed (for g and G) and the actual number of decimal digits printed for f and the like. I always assumed that that "maximum" referred to the fact that trailing zeroes (and eventually the decimal point) would not be printed, regardless of this value. Much to my surprise, the line of code: printf ("%.1g", 1.123); produced the output "1"; I had to use "%.2g" to get what I meant, i.e. one single decimal digit. Predictably enough "%.1f" does actually print "1.1"... Since other compilers seem to agree with this behaviour, I must be missing something. Would anybody kindly point me in the right direction? Thanks in advance -mario
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |