The function for converting a string to a floating point number. The function provided by standard C is atof (char *). c ++ Builder provides a function strtofloat (ansistring *), however, if you directly define a floating-point variable and convert the string to a single-precision floating-point variable, there may be problems with precision errors. The following is a simple example.
Char * strdemo = "0.00100 ";
Float fdat;
Fdat = atof (strdemo );
Showmessage (fdat );
AboveCodeThe computation result is: 0.00100000004749475, with a significant Conversion error.
The function definition for converting a string to a floating point: Double atof (const char * s );
The Return Value Type of the atof () function is double. If you assign a value to a single-precision floating point number, there must be a loss of precision. The cause is found, modify the float in the above Code to double and compile and run the program. The result is 0.001.
OK! Solve the problem.