Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: number comparison with a twist

by tobyink (Canon)
on Mar 02, 2020 at 15:37 UTC ( [id://11113640]=note: print w/replies, xml ) Need Help??


in reply to number comparison with a twist

This should work?

my $fmt = '%.02f'; if ( sprintf($fmt, $num1) eq sprintf($fmt, $num2) ) { print "they're the same, to two decimal places\n"; }

Another common way is to decide upon a maximum allowable difference between them, for example, 0.005, and compare them like this:

my $diff = 0.005; if ( abs($num1-$num2) < $diff ) { print "they're close enough\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-28 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found