473,238 Members | 3,787 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,238 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 8670
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: tarmat | last post by:
I'm trying to create a function that will turn a float into a std::string that always shows the number to two decimal places. I have the following but it doesn't give the desired output: ...
8
by: Woodster | last post by:
I am starting to use templates and have managed to figure out how to use std::string, std::map and make_pair successfully so far (Yeah I know - not much of a big step but I'm getting there) ...
5
by: Mr Fish | last post by:
Is it possible for me to record floats in a std::stringstream with 100% accuracy? If so how? Here's a little prog that demonstrates how the default ss loses accuracy ...
1
by: kathy | last post by:
I have code: std::stringstream sStream; double pi = 3.14159; .... sStream << pi; //????????????? std::str = sStream.str(); //I want str show the scientific format.
1
by: Gernot Frisch | last post by:
hi, is it possible - or better: why hasn't it been in the std - to add this function: ofstream os("xy"); int my_int = 0; double my_double =123.12; os << std::format("8.3f", my_double) <<...
1
by: Gary Wessle | last post by:
hi the code below is giving me what I want but it is very ugly. and will not work for a long list of different length numbers. could you please look at it and comment. thank you the...
3
by: Anjo Gasa | last post by:
I'm having some cases where setprecision in combination with iostreams gives some unepected behavior. Consider the following program: #include <iostream> #include <iomanip> int _tmain(int...
3
by: PengYu.UT | last post by:
Hi, I setprecision to be 100 for both cases. I'm wondering why the number of digits are different. Also, for a double number, I think any digits that are longer than 15 (or 16) are not...
4
by: Johannes Bauer | last post by:
Hello group, I've a simple problem with the precision specifiers of stringstream. Let's say I have this: double x = 123.4567890; std::stringstream Strm; Strm.precision(4); Strm <<...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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...

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.