http://qs321.pair.com?node_id=293475


in reply to My floating point comparison does not work. Why ?

Your reasoning is sound. I have only a small remark. If you want to print the two numbers to show their differences, increase the number of decimals.

#!/usr/bin/perl -w use strict; my ( $number, $premium, $expected ); $number = 1.80; $premium = $number * ( 1 + 10/100 ); # 1.8 + 10% of 1.8 $expected = 1.98; # As we know 1.8 + 10% of 1.8 is 1.98 printf "Number 1 : %20.19f\n", $premium ; printf "Number 2 : %20.19f\n", $expected ; print "Not" if ( $expected != $premium ); print "Equal !! "; __END__ Number 1 : 1.9800000000000002043 Number 2 : 1.9799999999999999822 NotEqual !!