The C standard library functions
atof
and
strtod
are not rounding off any decimal places that can be hold by a
double
.
The rounding occurs probably when printing them out. To show all significant digits that can be hold by a double precision value use the
[s]printf
format "%.16G" (using the scientific format here to avoid leading / trailing zeroes for very small / large numbers).
A double precision value can hold 16 significant decimal digits (more precise: DBL_MANT_DIG * log10(2) = 15.95)
If the CSV has been created by printing double precision values, you should have no loss of precision besides those introduced by converting to string and back to floating point.
If the values in the file have more significant digits you must use a decimal number format. Note the term "significant" here. The CSV file may have been created by printing double precision values with more digits (e.g. using "%.18G") but the additional digits are not significant then (they are random).
Using
long double
is not an option with Visual C/C++ because it does not support operations with that type.
If you need a higher precision, use a C++ decimal type implementation like
Chapter 1. Boost.Multiprecision - 1.62.0[
^].