I have this:
double myDecimal = static_cast<double>(atoi(arg_vec[1]));
cout << myDecimal << endl;
But why when I pass the argument like this:
./MyCode 0.003
It prints 0
instead of 0.003
.
I have this:
double myDecimal = static_cast<double>(atoi(arg_vec[1]));
cout << myDecimal << endl;
But why when I pass the argument like this:
./MyCode 0.003
It prints 0
instead of 0.003
.
atoi() converts to an integer, you want atof(), which converts to a double
Since you're using C++, you can also use stringstreams:
istringstream ss(arg_vec[1]);
double d;
ss >> d;