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

formatting question

Hello All,

I have a following piece of code in C that I need to rewrite to C++.
However I just don't seem to be able to understand the format rules in
C.

The C code look like this:

I have two doubles x and y which has a value. Now their values are
written to
output with printf in the following way.

printf("%1f %3.2e\n",x,y);

I have read in a book that for instance %5.4f means write the float
with 5 digit
widt where 4 digit are dedicated to the decimal portion. However why
can I then
print out values with more then one digit ????
Can anyone explain this to me ????
And then what does %3.2e means then ??
That I will get at most 3 digits ???
where 2 are dedicated to the decimal ???
How can I rewrite this to C++ using cout to write to output ??
Thank you in advance

Jul 23 '05 #1
1 2064
wo*********@yahoo.com wrote:
I have a following piece of code in C that I need to rewrite to C++.
However I just don't seem to be able to understand the format rules in
C.

The C code look like this:

I have two doubles x and y which has a value. Now their values are
written to
output with printf in the following way.

printf("%1f %3.2e\n",x,y);

I have read in a book that for instance %5.4f means write the float
with 5 digit
widt where 4 digit are dedicated to the decimal portion.
Kind of. 5 would be the width of the whole field and 4 is the decimal
digits after the dot. If the number doesn't fit in 5 symbols considering
leading digits (before the decimal point) and the sign and the dot itself,
then the width is ignored.
However why
can I then
print out values with more then one digit ????
Because the width is ignored if the number doesn't fit.
Can anyone explain this to me ????
Get a good book.
And then what does %3.2e means then ??
It means to print out in scientific format with two decimal digits after
the floating point. The width 3 is not going to be enough, so it will be
ignored.
That I will get at most 3 digits ???
No. You will get 2 digits after the dot.
where 2 are dedicated to the decimal ???
Yes.
How can I rewrite this to C++ using cout to write to output ??


Read about 'fixed' and 'scientific' manipulators and also 'setprecision'
and 'setw', although the latter is not that important.

V
Jul 23 '05 #2

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

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
4
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I...
4
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
25
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold"...
1
by: Russell Mangel | last post by:
I am using VS2005. When I paste source code into the code window, VS2005 formats like the following: public MsgRecipientReader() : base() { }
7
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
10
by: Lyn | last post by:
Hi, I would like to make a bound text box not visible if it is empty (not just disable it). This option is not available from the standard conditional formatting feature (at least, not that I can...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.