I am trying to read values that are written as -0.49430978D-02, but they are only coming in as -0.49430978. I have the characters saved in a string vs and have attempted both
myval = stod(vs)
as well as
sscanf(vs.c_str(), "%le", &myval)
but both of them fail to read the exponent in the scientific notation. Is it because it is D and not E? How do I read this value correctly in c++?
The D format is an uncommon floating point representation common to some Fortran implementations to indicate double precision (or greater). AFAIK, all other environments use E for floating point and do not indicate the underlying precision.
I think your only choice is to read the value as a string, replace any D characters with E and then finish processing with strtod() or equivalent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With