shahmeer arhsad
shahmeer arhsad

Reputation: 49

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

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.

Upvotes: 0

Views: 57

Answers (0)

Related Questions