Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   format for double for printf (http://www.velocityreviews.com/forums/t556908-format-for-double-for-printf.html)

RoS 12-03-2007 07:21 AM

format for double for printf
 
the format for conversion of double in the function printf is
"%f" or "%lf" or both?

for example
printf("%f", (double)0.0);
printf("%lf", (double)0.0);
are both ok?

Good morning
Thank you

Thomas X. Iverson 12-03-2007 07:51 AM

Re: format for double for printf
 
it seems like that in c there is no need to print a double varible
with %lf format
%f is ok
but for long interger , u should use %ld

RoS wrote:
> the format for conversion of double in the function printf is
> "%f" or "%lf" or both?
>
> for example
> printf("%f", (double)0.0);
> printf("%lf", (double)0.0);
> are both ok?
>
> Good morning
> Thank you


Ian Collins 12-03-2007 07:57 AM

Re: format for double for printf
 
RoS wrote:
> the format for conversion of double in the function printf is
> "%f" or "%lf" or both?
>
> for example
> printf("%f", (double)0.0);
> printf("%lf", (double)0.0);
> are both ok?
>

Yes they are equivalent, the l modifier has no effect for the f specifier.

--
Ian Collins.

pete 12-03-2007 01:49 PM

Re: format for double for printf
 
Ian Collins wrote:
>
> RoS wrote:
> > the format for conversion of double in the function printf is
> > "%f" or "%lf" or both?
> >
> > for example
> > printf("%f", (double)0.0);
> > printf("%lf", (double)0.0);
> > are both ok?
> >

> Yes they are equivalent,
> the l modifier has no effect for the f specifier.


That's the case for C99.
For C89,
a function call to printf is undefined
if "%lf" is the first argument.

--
pete

vippstar@gmail.com 12-03-2007 03:14 PM

Re: format for double for printf
 
On Dec 3, 3:49 pm, pete <pfil...@mindspring.com> wrote:
> Ian Collins wrote:
>
> > RoS wrote:
> > > the format for conversion of double in the function printf is
> > > "%f" or "%lf" or both?

>
> > > for example
> > > printf("%f", (double)0.0);
> > > printf("%lf", (double)0.0);
> > > are both ok?

>
> > Yes they are equivalent,
> > the l modifier has no effect for the f specifier.

>
> That's the case for C99.
> For C89,
> a function call to printf is undefined
> if "%lf" is the first argument.


The first? "%d %lf" is not undefined?

Keith Thompson 12-03-2007 07:24 PM

Re: format for double for printf
 
vippstar@gmail.com writes:
> On Dec 3, 3:49 pm, pete <pfil...@mindspring.com> wrote:
>> Ian Collins wrote:
>>
>> > RoS wrote:
>> > > the format for conversion of double in the function printf is
>> > > "%f" or "%lf" or both?

>>
>> > > for example
>> > > printf("%f", (double)0.0);
>> > > printf("%lf", (double)0.0);
>> > > are both ok?

>>
>> > Yes they are equivalent,
>> > the l modifier has no effect for the f specifier.

>>
>> That's the case for C99.
>> For C89,
>> a function call to printf is undefined
>> if "%lf" is the first argument.

>
> The first? "%d %lf" is not undefined?


Yes, "%d %lf" is undefined for C89/C90's printf. He said "if", not
"if and only if".

(Incidentally, given printf("%d %lf", x, y), the first *argument*
isn't %d; it's the string "%d %ld".)

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Walter Roberson 12-03-2007 07:42 PM

Re: format for double for printf
 
In article <47540953.3C97@mindspring.com>,
pete <pfiland@mindspring.com> wrote:
>Ian Collins wrote:
>>
>> RoS wrote:
>> > the format for conversion of double in the function printf is
>> > "%f" or "%lf" or both?


>> Yes they are equivalent,
>> the l modifier has no effect for the f specifier.


>That's the case for C99.
>For C89,
>a function call to printf is undefined
>if "%lf" is the first argument.


And just to confuse matters, in C89, "%Lf" *is* defined and
indicates that the corresponding argument is long double .
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell


All times are GMT. The time now is 06:48 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.