468,315 Members | 1,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

double format specification

JK
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;
dVal = fTick * fLotSize * iDeno;

printf ("dVal : %g dInt : %g fTick: %g\n", dVal, dInt, fTick);

This is printing the output as :

dVal : 100 dInt : 0.01 fTick: 1e-04

If I use the format type "f" instead of "g" it prints the following
output

dVal : 99.999997 dInt : 0.010000 fTick: 0.000100

Here is my doubt. I always want the output in dddd.dddd ( where
dddd is one more decimal digits. It can go upto 10)
What should I give as the format specification to print the ouput in
the dddd.dddd format ?
Please help to resolve this problem..
FYI: I use g++ compiler (linux-gnu-2.4).
Jun 27 '08 #1
2 3380
On Jun 9, 3:13 pm, JK <jayesh.bab...@gmail.comwrote:
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;
dVal = fTick * fLotSize * iDeno;

printf ("dVal : %g dInt : %g fTick: %g\n", dVal, dInt, fTick);

This is printing the output as :

dVal : 100 dInt : 0.01 fTick: 1e-04

If I use the format type "f" instead of "g" it prints the following
output

dVal : 99.999997 dInt : 0.010000 fTick: 0.000100

Here is my doubt. I always want the output in dddd.dddd ( where
dddd is one more decimal digits. It can go upto 10)
What should I give as the format specification to print the ouput in
the dddd.dddd format ?
Please help to resolve this problem..
FYI: I use g++ compiler (linux-gnu-2.4).
The printf is a C language function and not a C++ function. Use cout
instead.
Jun 27 '08 #2
sh*******@yahoo.com wrote:
...
The printf is a C language function and not a C++ function. Use cout
instead.
printf is still part of C++ as well. Still, it is better to use
std::ostream.
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Sybren Stuvel | last post: by
7 posts views Thread by Chris Croughton | last post: by
2 posts views Thread by LUIS FAJARDO | last post: by
10 posts views Thread by Bryan Parkoff | last post: by
3 posts views Thread by =?Utf-8?B?U2NvdHQ=?= | last post: by
21 posts views Thread by Aman JIANG | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.