Problem with Turbo C and floating point

Rob Carriere rob at kaa.eng.ohio-state.edu
Wed Aug 17 05:42:42 AEST 1988


In article <1817 at akgua.ATT.COM> brb at akgua.ATT.COM (Brian R. Bainter) writes:
> [...]
>If the number in the string is for example 9999999.99 it ends up in
>the float as 10000000.00000 and a number entered as 1111111.11 ends
>up in the float as 1111111.12500.
> [...]

Doing a quick digit count, it looks as if you are up against the
precision limit of float.  If this is true (check your Turbo docs for
the float format TC uses, I don't know), then the solution is simply
to use doubles, and change the sscanf conversion character
correspondingly.  You will eventually have to do this anyway, as ANSI
seems to have decided, in its' infinite wisdom, that reading floats
(as opposed to doubles) is a no-no.

Rob Carriere



More information about the Comp.lang.c mailing list