Connecting Tech Pros Worldwide Help | Site Map

std::setprecision and scientific format

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 08:16 PM
Woodster
Guest
 
Posts: n/a
Default 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

  #2  
Old July 19th, 2005, 08:16 PM
Woodster
Guest
 
Posts: n/a
Default Re: std::setprecision and scientific format

In article <MPG.1a1f01dc56c9edb798968c@news.westnet.com.au> , mirror@
127.0.0.1 says...

Sorry the line
[color=blue]
> 04e+01° C[/color]

should read

4e+01° C

there is no leading 0
  #3  
Old July 19th, 2005, 08:16 PM
Senthilvel Samatharman
Guest
 
Posts: n/a
Default Re: std::setprecision and scientific format

Woodster wrote:
[color=blue]
> 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?[/color]

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";
[color=blue]
>
>
> Thanks in advance
>
> Sean Hannan[/color]

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.