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 !!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|