473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

format for double for printf

RoS
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
Dec 3 '07 #1
6 16695
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
Dec 3 '07 #2
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.
Dec 3 '07 #3
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
Dec 3 '07 #4
On Dec 3, 3:49 pm, pete <pfil...@mindspring.comwrote:
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?
Dec 3 '07 #5
vi******@gmail.com writes:
On Dec 3, 3:49 pm, pete <pfil...@mindspring.comwrote:
>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) <ks***@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"
Dec 3 '07 #6
In article <47***********@mindspring.com>,
pete <pf*****@mindspring.comwrote:
>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
Dec 3 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: John Lenton | last post by:
Is there any reason python's printf-style formatting is missing the (C99) '%a' specifier? I'm sorry if this has been asked and answered before; I can't find it on google ('%a' is a very awkward...
6
by: J | last post by:
Would anyone know if there a type tag to format a double? I have f for floating point, but cannot find one for double.
5
by: google | last post by:
first, a little background... i have a C program which preprocesses some data, and then outputs the results into a text file. that text file, in turn, is used as input to a FORTRAN...
2
by: mdeaver2003 | last post by:
I'm trying to output a double using a precision that varies, governed by the value of a precision variable. In C I can do it like this: double pi = 3.14159; int prec = 4; printf( "%.*f",...
4
by: MC | last post by:
In C, printf allows us to specify a runtime (non-constant) field width of a formatted value by using the * character. Is there something like that for System.String.Format? In C#, I find myself...
4
by: bobm2005 | last post by:
Whatever format I try in Printf, an 'E' format number nearly always has a leading non-zero:- 1.2345E7 -9.3456E8 etc. Is it possible to force it (printf) always to have leading zero? ...
12
by: naunetr | last post by:
in program below #include <stdio.h> int main() { int id = 123, io = 0123, ih = 0x123; long ld = 1234567L, lo = 01234567l, lh = 0X1234567L; float f = 123.456f; double d = 01234.56789L;
2
by: JK | last post by:
The following is a sample program I wrote.. float fTick = 0.0001; float fLotSize = 100; int iDeno = 10000; double dVal; double dInt; dInt = fTick * fLotSize;
30
by: Adam | last post by:
Hi, I have a simple printf-like function: int print(const char *format, ...) { char buffer; va_list argptr; int i;
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.