I have a code that looks like the following
#include <iostream>
#include <sstream>
using namespace std;
int main(){
string s = "-1.42-14";
stringstream ss;
ss << s;
double a ;
ss >> a;
cout << "a = " << a << endl;
}
I run this code and I get a = -1.42,but I want a = -1.42e-14.
what should I do
You can simply read in both parts separately and combine them manually:
Output:
Note: Given that floating point types are only an approximation of real numbers, when you perform the same calculation by different means, you often arrive at a slightly different value.