Correct way to set maximum double precision for ostringstream

Turning to

How to print double value with full precision using cout?

and

What is the meaning of numeric_limits <double> :: digits10

I'm a little confused.

Should I use:

ss.precision(std::numeric_limits<double>::digits10);

or

ss.precision(std::numeric_limits<double>::digits10 + 2);

to get maximum double precision?

+3
source share
2 answers

it depends on the number of "decimal component" that you have in the data.

std :: numeric_limits :: digits10 will give the maximum number of "floating component"

ios_base :: precision indicates the number of digits (decimal + floating components) to display.

if your decimal component is always less than 100 (-99 to 99), the code below always gives maximum precision.

ss.precision(std::numeric_limits<double>::digits10 + 2);
+1

numeric_limits <double> :: digits10, , , std::numericlimits<double>::digits10:

, .

, ss.precision, ; +2, - + 2 , .

, , mpir, gmp, mpfr

0

Source: https://habr.com/ru/post/1734345/


All Articles