Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read double scientific notation with 'D' as exponent prefix in C++

Tags:

c++

string

io

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++?

like image 530
drjrm3 Avatar asked Dec 03 '25 15:12

drjrm3


1 Answers

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.

like image 93
wallyk Avatar answered Dec 06 '25 05:12

wallyk