S
skerrick32
I am performing some basic arithmetic on some variables and then using
a numeric equality operator to see if it returns what I think it should
be.
I am printing out the results and sure enough it is as expected. My
problem is when I use the numeric equality operator it returns false
even though my print statement showed that it should be true. The
string equality operator works(does return true) but I am curious what
is going on that is preventing the numeric version to work. Since I am
working strictly with numbers I would like to use the numeric version.
Here is the code that I am testing with.
use strict;
# define some variables
my $var_1 = 596181.10112 ;
my $var_2 = 600;
my $var_3 = 715793.0585;
my $var_4 = -99.7375378599037;
my $var_5 = 200;
my $var_6 = 3;
# perform some arithmetic
my $my_num = (($var_1*$var_2)/$var_3);
$my_num = $my_num + $var_4 - $var_5;
$my_num = $my_num * $var_6;
# print result
print "my_num: $my_num\n";
# See which equality operator works. Why does numeric version not
work?????
if ($my_num == 600) {
print "Numeric equality operator evaluated to true. good.\n";
}
if ($my_num eq 600) {
print "String equality operator evaluated to true. \n";
}
Thanks
Eric
a numeric equality operator to see if it returns what I think it should
be.
I am printing out the results and sure enough it is as expected. My
problem is when I use the numeric equality operator it returns false
even though my print statement showed that it should be true. The
string equality operator works(does return true) but I am curious what
is going on that is preventing the numeric version to work. Since I am
working strictly with numbers I would like to use the numeric version.
Here is the code that I am testing with.
use strict;
# define some variables
my $var_1 = 596181.10112 ;
my $var_2 = 600;
my $var_3 = 715793.0585;
my $var_4 = -99.7375378599037;
my $var_5 = 200;
my $var_6 = 3;
# perform some arithmetic
my $my_num = (($var_1*$var_2)/$var_3);
$my_num = $my_num + $var_4 - $var_5;
$my_num = $my_num * $var_6;
# print result
print "my_num: $my_num\n";
# See which equality operator works. Why does numeric version not
work?????
if ($my_num == 600) {
print "Numeric equality operator evaluated to true. good.\n";
}
if ($my_num eq 600) {
print "String equality operator evaluated to true. \n";
}
Thanks
Eric