I have read several topics about the display of floating point numbers display in C++ and I couldn\'t find a satisfying answer.
My question is: how
Have you looked at std::max_digits10
?
From cppreference:
The value of
std::numeric_limits
is the number of base-10 digits that are necessary to uniquely represent all distinct values of the type::max_digits10 T
, such as necessary for serialization/deserialization to text. This constant is meaningful for all floating-point types.
The implication of this (and is how I use it) is that the text output can be copy/pasted into another program and the number will represent the same number.
Now, I must say that my work-horse format is always right-justified %23.16E
, and I use engineering judgement for the last few digits. I like it because is is sufficient for the sign, the exponent, and sixteen digits.
-----------------------
-1.1234567812345678E+12
Now, notice that digits
of precision and decimal digits
of precision are not necessarily the same thing.