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

Re^3: Equality checking for strings AND numbers

by Anonymous Monk
on Jul 16, 2007 at 03:00 UTC ( [id://626767]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Equality checking for strings AND numbers
in thread Equality checking for strings AND numbers

Check this page out, It has tests to find variables types, and how to convert them. You can test if a value is an int, if it is convert it to a real and then do the comparison.

http://search.cpan.org/~dwheeler/Data-Types-0.06/lib/Data/Types.pm.

With this you should be able to get it to at least the same variable type. If both become float types and and you compare 10.0 to 10.00, you should end up with equality... Another though that you can do is set up a tolerance for precision on number comparisons;

Instead of if a == b

do if (absolute value of (a - b)) > .0001 then .....

Just some thoughts. I personally haven't done a lot with Perl yet.

  • Comment on Re^3: Equality checking for strings AND numbers

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found