Double data type adding changing the digits after decimal point c++

60 Views Asked by At

I am inputing some decimal data from a file using ifstream. The double column that I am using changes the decimal values itself.

Example if the value in file is 0.714000 it will be changed to 0.71399999999999997. What can I do to keep the value same as the file.

while (getline(infile, line)) {
    string error_message = "";
    std::cout << std::fixed << std::setprecision(6);
    double decimal_value=0.0
    istringstream ss(line);
    ss >> decimal_value;

decimal_value variable should have 0.714000 instead of 0.71399999999999997 ,as I am using these values for some maths calculations and this small difference changes the final equation result.

0

There are 0 best solutions below