in reply to Unwanted implicit conversion to float

You've apparently not learned that (1/10) cannot be precisely represented in binary floating point. It's an infinite repeating expansion, which has to be truncated at some point (heh). Multiplying that by 10 does not yield 1.0 any more.

If you want precise pennies, you must count in pennies (using integer values for pennies).

-- Randal L. Schwartz, Perl hacker

  • Comment on Re: Unwanted implicit conversion to float

Replies are listed 'Best First'.
(tye)Re: Unwanted implicit conversion to float
by tye (Sage) on Mar 12, 2001 at 23:08 UTC

    I'm curious... I recall this being a bigger problem in older versions of Perl and patches being applied such that Perl became smart enough to avoid including "9999999" or "0000001" on the end of floating point numbers.

    So is this a case where round-off is making the result "a bit off" from the closest possible value and this prevents the "smarter" code from avoiding the extra trailing digits? I wouldn't think that adding "1" would cause that problem.

    Update: Okay, we're doing a running total here so there is round-off involved. Sorry for the confusion.

            - tye (but my friends call me "Tye")
Re: Re: Unwanted implicit conversion to float
by 2501 (Pilgrim) on Mar 12, 2001 at 23:08 UTC
    *cry* sometimes ignorance is bliss...

    who wants the bill for the head imprint in my desk? You or turnstep ? :)