Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Comparing results of math operations

by zentara (Archbishop)
on Apr 16, 2014 at 09:50 UTC ( #1082474=note: print w/ replies, xml ) Need Help??

in reply to Comparing results of math operations

Here is another textbook example which demonstrates the problem. You need to specify how many digits of accuracy you need for the comparison, and round your floats off accordingly.

#!/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 !!

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Comment on Re: Comparing results of math operations
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082474]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2015-11-26 00:37 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (694 votes), past polls