Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Strange int() result

by choroba (Abbot)
on Jun 18, 2014 at 09:19 UTC ( #1090278=note: print w/ replies, xml ) Need Help??


in reply to Strange int() result

35784.45 * 100 is in fact

$ perl -e 'printf "%.15f\n", 35784.45 * 100' 3578444.999999999534339

See What every computer scientist should know about floating-point arithmetic for explanation.

int just removes the part after the dot (for positive numbers, at least). Its documentation contains a list of functions you can use to get more pleasant results.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Strange int() result
Download Code
Re^2: Strange int() result
by RonW (Pilgrim) on Jun 18, 2014 at 17:16 UTC

    3578444.999999999534339 suggests you are running into the limits of your Perl/PC combination's floating point handling.

    Your problem would be better handled with fix point arithmetic. Look at Math::BigInt.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2014-07-31 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (248 votes), past polls