Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Floats with trailing zeros as a hash key

by jkahn (Friar)
on May 09, 2003 at 22:59 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-07-05 00:31 GMT
Find Nodes?
    Voting Booth?

    No recent polls found