Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: number comparison with a twist

by parv (Vicar)
on Mar 02, 2020 at 15:42 UTC ( #11113642=note: print w/replies, xml ) Need Help??


in reply to Re^2: number comparison with a twist
in thread number comparison with a twist

Does that mean you may also be getting data with built-in imperfect decimal representation? Please have clear rounding rules before doing anything serious.

Replies are listed 'Best First'.
Re^4: number comparison with a twist
by anotherguest (Novice) on Mar 02, 2020 at 15:54 UTC
    Is it possible? I guess it is. After all, I have no control over the API. Then again, the prizes I get are end prizes including VAT so they MUST always be describable in whole cents. This is also the reason the database was set up to store them as integer cents, to avoid any rounding issues (that worked very well, right?).
    So, truncating to 2 decimal digits is The Right Thing(TM) in this case.
      A quibble: truncating is the wrong thing to do, and is the problem with your original int() solution in the first place. Rounding to the nearest cent is the right thing to do (which can be done through round() as I suggested, or using the sprintf() solutions that others have mentioned).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2020-10-26 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (252 votes). Check out past polls.

    Notices?