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

streams and floaters

I have a double that contains the value 1000000. I want to print
"1000000". Just doing this:

str << doub;

results in "1e+006". Attempting this:

str << std::fixed << doub;

results in "1000000.000000"

str << std::fixed << std::noshowpoint << doub

results in the same.
>From what I am reading, the last should be exactly what I want but it
isn't resulting in what I want. What is the correct way?

Aug 28 '06 #1
3 1857
BRG
Noah Roberts wrote:
I have a double that contains the value 1000000. I want to print
"1000000". Just doing this:

str << doub;

results in "1e+006". Attempting this:

str << std::fixed << doub;

results in "1000000.000000"

str << std::fixed << std::noshowpoint << doub

results in the same.
>>From what I am reading, the last should be exactly what I want but it
isn't resulting in what I want. What is the correct way?
str << std::fixed << std::noshowpoint << std::setprecision(0) << doub

should work.

Brian Gladman
Aug 29 '06 #2

BRG wrote:
Noah Roberts wrote:
I have a double that contains the value 1000000. I want to print
"1000000". Just doing this:

str << doub;

results in "1e+006". Attempting this:

str << std::fixed << doub;

results in "1000000.000000"

str << std::fixed << std::noshowpoint << doub

results in the same.
>From what I am reading, the last should be exactly what I want but it
isn't resulting in what I want. What is the correct way?

str << std::fixed << std::noshowpoint << std::setprecision(0) << doub
Doesn't setprecision(0) also shut off after the decimal if I have a
value that needs it?

Aug 29 '06 #3
BRG
Noah Roberts wrote:
BRG wrote:
>Noah Roberts wrote:
>>I have a double that contains the value 1000000. I want to print
"1000000". Just doing this:

str << doub;

results in "1e+006". Attempting this:

str << std::fixed << doub;

results in "1000000.000000"

str << std::fixed << std::noshowpoint << doub

results in the same.

From what I am reading, the last should be exactly what I want but it
isn't resulting in what I want. What is the correct way?
str << std::fixed << std::noshowpoint << std::setprecision(0) << doub

Doesn't setprecision(0) also shut off after the decimal if I have a
value that needs it?
Yes.

If this matters to you you will need to test if your number is an
integer and set the argument to setprecision accordingly. Something like:

str << std::fixed << std::noshowpoint
<< std::setprecision(x == std::floor(x) ? 0 : 5) << x;

Brian Gladman
Aug 30 '06 #4

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

Similar topics

8
by: Ronald Legere | last post by:
The new itertools stuff is pretty cool. One thing that bothers me though is that there seems to be no way to copy an iterator. How does one work around this? Is there a trick that I am missing? ...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
8
by: bonj | last post by:
hello I hope somebody can help me get my head around this area of 'stream' programming... I know that streams are very fashionable nowadays so hopefully there'll be lots of replies. ;-) ...
5
by: Andrey Tarasevich | last post by:
Hello Consider the following simple piece of HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html style="width: 100%; height: 100%"> <body...
11
by: Kobu | last post by:
I have a question about C's abstract "streams" (that I can't seem to FULLY understand from reading several tutorials). Streams seems to suggest that input can be treated continously if needed....
2
by: Peter Rilling | last post by:
One nice thing about collections and arrays is that they implement the IEnumerator and IEnumerable interfaces which allow for more then one iterator to walk the list of items without affecting the...
2
by: bonk | last post by:
Hello how do I connect streams in c# ? Imagine the followung scenario: I have a StreamWriter that writes Text to a Stream. How can I tell that Stream to pass that Data to another Stream...
1
by: Chris | last post by:
I'm reading up on streams and I have two articles that seem to conflict with each other. One article describes streams and lists a few of the major ones (FileStream, Memory Stream, Network...
2
by: Abhishek | last post by:
what are the STDUPDATE, STDERR, STDOUT and STDIN streams and how does one access these streams in C language. I am aware of the function fprintf(FILE *fp, char * format, char *s) which puts the...
4
by: floppyzedolfin | last post by:
Hello! I'm actually encoding an encryption / decryption program. The encryption programes takes a file path in parameter, and encrypts the contents of the file and stores that into another file. ...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.