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

Re: Floats with trailing zeros as a hash key

by jkahn (Friar)
on May 09, 2003 at 22:59 UTC ( [id://257028]=note: print w/replies, xml ) Need Help??


in reply to Floats with trailing zeros as a hash key

I am going to guess that my suggestion (below) is too big a rewrite for the code you're working on, but let me make it anyway:

Store prices as integer cents.

There are several reasons that C programs usually store prices as integer amounts of pennies, and then convert to dollars at the last minute:

  • Fractions of a penny don't make sense (cents?)
  • no roundoff issues

This might be one of those cases for you, too. 4520 pennies will never get rounded to 452 pennies, but 45.20 dollars (or euros) will get rounded to 45.2 by internal number-to-string conversions.

Just my $0.02 er, 2¢

  • Comment on Re: Floats with trailing zeros as a hash key

Replies are listed 'Best First'.
Re: Re: Floats with trailing zeros as a hash key
by hardburn (Abbot) on May 10, 2003 at 00:17 UTC

    Wow, that's a good idea. Wish I had heard it a week ago (:

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found