471,852 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

std::setprecision and scientific format

I am using the std::setprecision function to format variables of type
double in a string however I am unsure how to stop this appearing in
scientific notation.

For example

std::stringstream buffer;

buffer << setprecision(1) << 40.0 << "° C";

produces the string

04e+01° C

in buffer.

Ideally I would like this to be

40° C

but I think I will have to settle for 40.0° C if I want to cater for
other values where the single decimal place is required.

How do I use setprecision an not get scientific notation as the output?

Thanks in advance

Sean Hannan
Jul 19 '05 #1
2 8532
In article <MP************************@news.westnet.com.au> , mirror@
127.0.0.1 says...

Sorry the line
04e+01° C


should read

4e+01° C

there is no leading 0
Jul 19 '05 #2
Woodster wrote:
I am using the std::setprecision function to format variables of type
double in a string however I am unsure how to stop this appearing in
scientific notation.

For example

std::stringstream buffer;

buffer << setprecision(1) << 40.0 << "° C";

produces the string

04e+01° C

in buffer.

Ideally I would like this to be

40° C

but I think I will have to settle for 40.0° C if I want to cater for
other values where the single decimal place is required.

How do I use setprecision an not get scientific notation as the output?
Use the manipulator "fixed" to get rid of scientific notation..
See John Bell's example for your previous post...
buffer << fixed << setprecision(3) << 40.0 << " C";


Thanks in advance

Sean Hannan


Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by tarmat | last post: by
8 posts views Thread by Woodster | last post: by
5 posts views Thread by Mr Fish | last post: by
1 post views Thread by Gernot Frisch | last post: by
1 post views Thread by Gary Wessle | last post: by
3 posts views Thread by Anjo Gasa | last post: by
3 posts views Thread by PengYu.UT | last post: by
4 posts views Thread by Johannes Bauer | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

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.