in reply to simple arithmetic creates rounding errors

I don't think you can get rid of them, you just have to manage it. If you swap in the following line you'll get the results as you expect.
my $frac = sprintf("%.9g", ($num - $int) );
This is simply rounding to an arbitrary 9 decimal points. Obviously you need to look at the formulas you're working with but this should serve in a lot of cases.

UPDATE: I didn't notice you actually gave a sprintf example. So, Yes, that is the easiest way to get rid of this problem. Infact the O'Reilly Perl CookBook gives examples just like this.
---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re^2: simple arithmetic creates rounding errors
by Anonymous Monk on Jan 13, 2006 at 11:33 UTC
    Thanks reasonablekeith

    The "%.9g" fixed it. Unlike "%.3f" which produces .000 onto everything.

    Excellent!!!!

    I must look better through the cookbook next time :-)