By DogDog

2010-02-25 16:31:15 8 Comments

I need to prevent my double to print in scientific notation in my file,

when I do this

outfile << X;


@Rozuur 2010-02-25 16:43:34

Here's an example of usage

as per your question use

  std::cout << std::fixed << a << std::endl;

@Anonymous 2016-02-18 14:32:04

Better answer since it directly answers the question ('fixed').

@davecoulter 2010-02-25 17:28:48

To set formatting of floating variables you can use a combination of setprecision(n), showpoint and fixed. In order to use parameterized stream manipulators like setprecision(n) you will have to include the iomanip library:

#include <iomanip>

setprecision(n): will constrain the floating-output to n places, and once you set it, it is set until you explicitly unset it for the remainder of the stream output.

fixed: will enforce that all floating-point numbers are output the same way. So if your precision is set to 4 places, 6.2, and 6.20 will both be output as:


showpoint: will force the decimal portions of a floating-point variable to be displayed, even if it is not explicitly set. For instance, 4 will be output as:


Using them all together:

outfile << fixed << showpoint;
outfile << setprecision(4);
outfile << x;

@Ident 2015-08-20 13:53:43

What makes you think that showpoint makes any difference here? The decimal portion is always shown with 0's due to the precision.

@kayleeFrye_onDeck 2018-06-19 18:25:45

All I needed was to include <iomanip> and use setprecision(n)

@matiu 2013-10-07 10:17:54

All the above answers were useful, but none directly answer the question.

outfile << x;

I found the answer in @moogs link:

Here's a demo program:

@moogs 2010-02-25 16:33:37

Related Questions

Sponsored Content

17 Answered Questions

[SOLVED] When to use virtual destructors?

9 Answered Questions

5 Answered Questions

8 Answered Questions

[SOLVED] What is The Rule of Three?

1 Answered Questions

Java not formatting scientific notation double

2 Answered Questions

[SOLVED] Why do powers of 10 print in scientific notation at the 5th power?

1 Answered Questions

[SOLVED] How to disable scientific notation?

2 Answered Questions

Sponsored Content