-2
#include <iostream>

using namespace std;

int main()
{
    string str="-1.2300";
    double d = stod(str);
    cout<<d<<"\n";
}

output: -1.23

i am expecting output as following

-1.2300

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
sks
  • 157
  • 2
  • 7

1 Answers1

0

If that is what you want, then you need to use formatted output with a precision specifier:

printf("%.4f\n", d);

or specify the precision for cout:

cout.precision(4);
cout << fixed << d << "\n";
David Hoelzer
  • 15,862
  • 4
  • 48
  • 67