use "sprintf" to set the floating point field to 2 decimal places. (or
more, if you want them...)
$float1=-135.176 # final values before rounding
$float2=-135.184
$float1=sprintf("%.2f",$float1); # force $float1 to be rounded at 2
decimal places
$float2=sprintf("%.2f",$float2); # ditto $float2
print "$float1\n$float2\n";
if ($float1 == $float2) {
print " values are EQUAL\n";
}
else { print " values are NOT EQUAL\n"; }
the example above will return
-135.18
-135.18
values are EQUAL
change
$float1 = 255.733
$float2 = 255.735
and this will return
255.73
255.74
values are NOT EQUAL
> -----Original Message-----
> From: John Deighan
>
> my $sum1 = -237.15;
> my $sum2;
> $sum2 += -26.35;
> $sum2 += -26.35;
> $sum2 += -26.35;
> $sum2 += -26.35;
> $sum2 += -26.35;
> $sum2 += -26.35;
> $sum2 += -26.35;
> $sum2 += -26.35;
> $sum2 += -26.35;
>
> print("sum1 = $sum1\n");
> print("sum2 = $sum2\n");
> if ($sum1 == $sum2) {
> print("EQUAL\n");
> }
> else {
> print("NOT EQUAL\n");
> }
>
> OUTPUT:
>
> sum1 = -237.15
> sum2 = -237.15
> NOT EQUAL
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs