473,396 Members | 2,018 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,396 software developers and data experts.

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 3600
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Sybren Stuvel | last post by:
Hi there! I'm a beginning Python programmer, and I like it a lot already. Since my Sharp Zaurus has a fairly complete Python environment including PyQT, I thought it would be the perfect...
1
by: L Mehl | last post by:
Hello -- Goal is to export data from tblData having this structure: dateRecord Date/Time textFrom Text 4 textTo Text 4 valueRecord Number Double (format = Standard, Dec Pl = 12)...
5
by: Skybuck Flying | last post by:
Hi, I have one more remaining "problem" with compiling a unix source code for windows/visual c/c++ 6.0 What does the isnan routine do ? Documentation says it checks for NaN ? What does that...
7
by: Chris Croughton | last post by:
Could someone who has access to the C89 specification please confirm whether the type long double existed in that spec.? The only copy I have is from the early draft stages, and it wasn't in that...
2
by: LUIS FAJARDO | last post by:
How can I convert from a double variable to string using standard ANSI-C. Thanks PS: I'm currently using _fcvt but is not enough.
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
15
by: shiniskumar | last post by:
How to convert string to double? Ive got a double variable dTot; its value is 5.037717235E7 when i did FreemarkerTools.formatDecimal(dTot) i got it as string "50377172.35". now i want to...
3
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
Hello, I would like to convert a double to a string and have the resulting string contain all of the original values after the decimal place. Currently, the problem that I am having is that the...
21
by: Aman JIANG | last post by:
hi I need to do this (convert double to string) fast, safe and portable. Is there any way to do this ? Except the ways following: 1. C++ I/O stream, stringstream (and boost::lexical_cast) 2....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.