c++ - How to retain 0s after decimal point, after converting string to double -


#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

Popular posts from this blog

c# SetCompatibleTextRenderingDefault must be called before the first -

C#.NET Oracle.ManagedDataAccess ConfigSchema.xsd -

c++ - Fill runtime data at compile time with templates -