R. Joseph Newton wrote: > > Rob Dixon wrote: > > > > It's also worth pointing out here that rational values are almost always what is > > wanted in this sort of situation. > > > > The (very nice indeed) Math::Fraction module lets you do just this. The only > > changes to the code are to initialise $value as a Math::Fraction object with > > > > my $value = frac -1 > > > > and to convert the value back to decimal for printing (otherwise > > the values would appear as ".. 1/10 1/5 3/10 .." etc.). > > > > HTH, > > > > Rob > > Sounds good. I've always tried to do any multiplication steps [at least within the > range expressed as true integers, which in Perl is pretty large] before dividing. > Mostly I just ahve a hunch that rounding errors will be minimized if numbers are > kept in integfer frm as long as possible.
That's effectively what this module does. It just keeps the divisor along with the dividend (0.1 is represented as the pair (1, 10)) so that you don't have to keep track of the scaling. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>