Full printing of digits after the decimal point

Hello everyone,

I’m utilizing a C++ API. Within the model I’ve developed, there’s a set of variables that I’m required to assign values to. They are of type double, and I need to extract all the digits after the decimal point. However, when I use:

double y2 = ampl.getVariable("y2").value;

and then print it using:

std::cout << "Value of y2: " << y2 << std::endl;

it displays the number with 4 digits after the decimal point. Is there a method to display the numbers after the decimal point as whole numbers?"
for example the real value for y2 is : 51.36333947849644 but the output of std::cout is 51.3634.

Hi @ae.naderi ,

To print a double with maximum precision use

std::cout << std::setprecision(std::numeric_limits<double>::digits10) << y << std::endl;

If you are going to redirect the output to a text file and read it back to double afterwards, use

std::cout << std::setprecision(std::numeric_limits<double>::max_digits10) << y << std::endl;

You will need to include the <iomanip> and <limits> headers.