[EMAIL PROTECTED] wrote: > I must be breaking some rules since I dont understand why comparison 2 is NOT > equal and comparision 2 is equal...
Do you mean 3 on the last one above ? > #!/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); I would use %f instead of %g for your floating point format type. return sprintf("%.${dp}f", $A) eq sprintf("%.${dp}f", $B); > } -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Unix-Users mailing list Perl-Unix-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs