如何正确地传递十进制值作为参数

nev*_*int 1 c++ decimal argument-passing

我有这个:

double myDecimal = static_cast<double>(atoi(arg_vec[1]));
cout << myDecimal << endl;
Run Code Online (Sandbox Code Playgroud)

但是当我传递这样的论点时为什么呢:

./MyCode 0.003   
Run Code Online (Sandbox Code Playgroud)

它打印0而不是0.003.

Mit*_*eat 7

atoi()转换为整数.你想要的atof().

或者你可以使用strtod().