"Marcus Jacobs" <ma*******@hotmail.com> wrote in message
I am encountering a precision issue while converting a text string to
a float using STRTOF. For example, at times a text string "736.00000"
(quotation marks added) is converted to "736.00001". I have null
terminated the strings. Does anyone know why does this happen and
how specifically to avoid this. This is quite critical to an applicaiton
that I am writing.
Regard floating point variables as having a small random error. It's not
really random, of course, but there is no exact representation of 0.1 in a
typical floating-point format.
If the the problem is critical to your application, there are several things
you can do. The best and probably easiest is to rewrite your algorithms so
that they can tolerate small errors.
The next thing to do is to use a fixed-point representation. If you only
need three digits of decimal places, you could store all results in longs as
value *1000 (this method is very useful if the values you are dealing with
are currency).
As a last resort, resign yourself to operating in decimal and write your own
floating point routines, maybe taking their operands as ASCII strings. This
will be slow and messy but should be perfectly accurate.