Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^4: Simple addition/subtraction not working

by JavaFan (Canon)
on Dec 02, 2011 at 09:59 UTC ( #941292=note: print w/replies, xml ) Need Help??

in reply to Re^3: Simple addition/subtraction not working
in thread Simple addition/subtraction not working

Sure, but my point wasn't that it wouldn't fit in a 64-bit int (or even a 32-bit int). It's that "just work in cents" may be interpreted by "multiply by 100; do your arithmetic; divide by 100". That works if your currency is dollars or euros, and you're dealing with grocery prices. It doesn't get you out of the floating point numbers if you have amounts in mills. (And if you do "multiply by 100, round to nearest integer", you will be working with integers even if the amounts where in mills, but your results are likely to be off).

Just want to make people aware that "just work with cents" may in some cases a tad less simple that multiplying by 100.

  • Comment on Re^4: Simple addition/subtraction not working

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://941292]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2018-06-24 21:36 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.