Note that there are two numbers of digits that are of interest:
If you take a decimal number, convert it to float, and convert it back to decimal, how many decimal digits are guaranteed to survive unchanged?
If you take a float, convert it to decimal, and convert it back to float, how many decimal digits are required to always get all bits of the original float correct?
For 32-bit float, the answers are 6 and 9, respectively. For 64-bit double, it's 15 and 17.
See: https://www.exploringbinary.com/number-of-digits-required-for-round-trip-con...
As an aside: when converting a string to a floating-point number, it is incorrect to round twice - i.e. you cannot implement strtof by calling strtod and then rounding double to float.
STL
-----Original Message-----
From: Boost
Where does boost::detail::lcast_get_precision<float>() come from, and why is it 9 ? Is it perhaps assuming some intermediate double conversion internally?
boost::detail::lcast_get_precision<double>() is 17, so no. My guess is that this is the precision that guarantees a perfect roundtrip. _______________________________________________ Unsubscribe & other changes: https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.boost...