I must be breaking some rules since I dont understand why comparison 2 is NOT 
equal and comparision 2 is equal...

#!/usr/bin/perl -w
use strict;
use warnings;

my $num1='2.80';
my $num2='2.8';
my $num3='2.80';

#comparison 1
if ($num1 == $num2) {
    print "The values are equal\n";
} else {
    print "The values are NOT equal\n";
}

#comparison 2
if ($num1 == ($num3 - .01)) {
    print "The values are equal\n";
} else {
    print "The values are NOT equal\n";
}

#comparison 3
if (equal($num1,($num3 - .01),2)) {
    print "The values are equal\n";
} else {
    print "The values are NOT equal\n";
}

sub equal {
    my ($A, $B, $dp) = @_;

    return sprintf("%.${dp}g", $A) eq sprintf("%.${dp}g", $B);
}

_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to