Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Comparing results of math operations (try integer)

by LanX (Canon)
on Apr 16, 2014 at 09:55 UTC ( #1082475=note: print w/ replies, xml ) Need Help??


in reply to Comparing results of math operations

Better avoid decimal fractions!

They can't always be transformed loss-free to binary fractions (see Re: eq vs ==)

But this works:

DB<107> $x=95*806 /100; => "765.7" DB<108> $y=13*589 /10; => "765.7" DB<109> $x <=> $y => 0

So just calculate with integers and shift the decimal point afterwards!

The deeper reason for this mess is that Humans have too many fingers ;-)

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re: Comparing results of math operations (try integer)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2015-07-07 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls