On Saturday, August 22, 2015 3:26:56 PM hw wrote:
> 
> Hi,
> 
> I have the following in a perl script:
> 
> 
>        if ($a != $b) {
>          print "e: '$a', t: '$b'\n";
>        }
> 
> 
> That will print:
> 
> e: '69.99', t: '69.99'
> 
> 
> When I replace != with ne (if ($a ne $a) {), it doesn't print.
> 
> 
> Is that a bug or a feature?  And if it's a feature, what's the explanation?
> 
> And how do you deal with comparisions of variables when you get randomly 
> either correct results or wrong ones?  It's randomly because this 
> statement checks multiple values in the script, and 69.99 is the only 
> number showing up yet which isn't numerically equal to itself (but equal 
> to itself when compared as strings).
> 

Most languages have a decimal type that you should use when you need exact 
math. I think for perl this is what you want:

http://search.cpan.org/~zefram/Math-Decimal-0.003/lib/Math/Decimal.pm

-- 
Fernando Rodriguez

Reply via email to