Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Strange int() result

by choroba (Chancellor)
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.

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

Replies are listed 'Best First'.
Re^2: Strange int() result
by RonW (Priest) 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?
[Your Mother]: Did I tell or show you? There is a leucistic Turkey Vulture around here all the time. I have a couple decent pictures.
[Your Mother]: Pure white (well, dirty white :P)
[erix]: as a kid I had a painted bunting -- beautiful
[Your Mother]: I would love to see one. It would be a lifer.
[Your Mother]: Wait… maybe I did see one last year…
[Your Mother]: I saw what I thought was a Cuban trogon but they are too impossibly rare / never seen in the US. That guy might have been what I actually saw.
[LanX]: Good Night guys!
[LanX]: :)
[erix]: ciao LanX
[Your Mother]: “A main wintering area is southern peninsular Florida, from the Florida Keys”

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-01-20 01:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (173 votes). Check out past polls.