Possible duplicates:
Examples of floating point inaccuracies
Is JavaScript math broken?
I need to convert some data from a txt file to a double value, and I use this function to do this: atof. The problem is that the value to be converted is 5.550000, and the atof function returns 5.5499999999999998, and this is a problem because I have to calculate the GPA with this number, and the retry is inaccurate. This is a function that reads data from a txt file:
void readNext(FILE* file,Lab* lab)
{
char line[100];
getline(file,line,100);
if (strcmp(line,"") == 0)
{
lab->is_null = 1;
return;
}
strcpy(lab->date,line);
getline(file,line,100);
lab->presence = atoi(line);
getline(file,line,100);
strcpy(lab->num_work,line);
getline(file,line,100);
lab->mark_work = atof(line);
getline(file,line,100);
lab->test_work = atof(line);
getline(file,line,100);
lab->current = atof(line);
getline(file,line,100);
lab->status_work = atoi(line);
getline(file,line,100);
}
source
share