Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display more decimals in the output console? [duplicate]

Tags:

c++

console

I want to output the value of a double in it's full precision. However, when using the cout function, it only displays the first 6 digits even though there is around 15-16 digits of precision.

How do I get my program to display the entire value, including the magnitude (power) component?

like image 307
Faken Avatar asked Aug 05 '09 07:08

Faken


1 Answers

Use the setprecision() manipulator:

http://www.cplusplus.com/reference/iostream/manipulators/setprecision/

You can also force scientific notation with the scientific manipulator:

http://www.cplusplus.com/reference/iostream/manipulators/scientific/

cout << scientific << setprecision(15) << my_number << endl;
like image 83
Amber Avatar answered Sep 20 '22 00:09

Amber