c++ - How to retain 0s after decimal point, after converting string to double -
this question has answer here:
#include <iostream> using namespace std; int main() { string str="-1.2300"; double d = stod(str); cout<<d<<"\n"; }
output: -1.23
i expecting output following
-1.2300
if want, need use formatted output precision specifier:
printf("%.4f\n", d);
or specify precision cout:
cout.precision(4); cout << fixed << d << "\n";
Comments
Post a Comment