Mail Archives: djgpp/1996/12/03/00:26:20
afonso AT inesca DOT inesca DOT pt wrote:
> char string[]="1.13";
> int result;
> ...
> result = (int)(atof(string)*100);
> ...
>
> I've got result = 112!!! not 113 as I wished, because
> the function atof() return is 1.29999... not 1.13 (and I only have
> an old i386).
> I think that problem is a bug of DJGPP Library V2.xx.
> Has someone noticed that problem and corrected it? If they
> have, please let me know about it.
Not a library bug. It's probably due to truncation. When you convert
floating point values to integer values, there is no rounding done.
Instead, everything after the decimal point is dropped. 1.1299999 *
100.0 is 112.9999, and will always be 112 when converted to an integer
unless you purposely round up.
-- Yamaha / XYZZ
mailto:scriven AT CS DOT ColoState DOT edu
mailto:scriven AT VIS DOT ColoState DOT edu
http://www.vis.colostate.edu/~scriven/
- Raw text -