Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > format for double for printf

Reply
Thread Tools

format for double for printf

 
 
RoS
Guest
Posts: n/a
 
      12-03-2007
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
 
Reply With Quote
 
 
 
 
Thomas X. Iverson
Guest
Posts: n/a
 
      12-03-2007
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

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      12-03-2007
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.
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      12-03-2007
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
 
Reply With Quote
 
vippstar@gmail.com
Guest
Posts: n/a
 
      12-03-2007
On Dec 3, 3:49 pm, pete <(E-Mail Removed)> 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?
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-03-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:
> On Dec 3, 3:49 pm, pete <(E-Mail Removed)> 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) <(E-Mail Removed)>
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"
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      12-03-2007
In article <(E-Mail Removed)>,
pete <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Double printf format... naunetr C Programming 14 03-14-2008 08:44 PM
printf format for double Joachim Schmitz C Programming 1 10-02-2007 04:44 PM
(void) printf vs printf whatluo C Programming 29 09-08-2005 05:42 PM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
bus error with printf line included, error without printf line? ben C Programming 4 06-26-2004 04:42 PM



Advertisments