in reply to strange arithmetic results
One workaround is to *impose* precision: here, you want equality up to the first two decimal places, so you could multiply your numbers by 100 and take the int() value of them to compare. Here's a subroutine:
sub cmp_dollar { my ($c, $d) = map { int( $_ * 100 ) } @_; $c == $d; }
This oughta deal with the trailing \n issue, too, as that will be ignored by the automagic string-number conversion.
perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: strange arithmetic results
by tommyw (Hermit) on Sep 25, 2001 at 17:24 UTC |