Re: Why not FP for Money?

From: Carlos Ribeiro (carribeiro_at_gmail.com)
Date: 09/23/04


Date: Thu, 23 Sep 2004 08:41:38 -0300
To: Chris Barker <barkmann@gmail.com>

On 22 Sep 2004 22:03:43 -0700, Chris Barker <barkmann@gmail.com> wrote:
> ... Personally, thinking of money it
> terms of significant digits would be fine with me. Is there really any
> point in keeping track of the pennies when talkin gof trillions of
> dollars?

In Brazil, there is tax for money transfers (all transfers to, from
and between accounts). It's 0.38% of each operation. Some operations
are really smal, just a few reals, and the tax is measured in cents.
For big operations -- those in the range of millions -- the tax gets
bigger, but still manageable. But when you sum up all the transfers,
the sum has to be exact to the cent. Imagine if you sum all transfers
done in one year, for accounting purposes. The number is really big --
in the order of billions. But the sum has to be precise to the cent.
 
(Ok, it's not trillions -- I'm only showing you and example of a
situation that stress the limits of numeric precision)

> """
> Beware! Floating point errors may bite you *even for non-fractional
> numbers*
> """
>
> I tried to address that in the OP. 64 bit IEEE FP carries a lot of
> digits! This isn't an issue till you get to quadrillions of dollars.
> The same issue comes up if you use standard integers, though then you
> will get overflow instead. If not handled right, that could REALLY
> give strange results! Fortunatly Python now automatically rolls over
> to long integers.

... and ...

> One interesting distiction here: binary vs. decimal and floating point
> vs. fixed point are orthoganal concepts that have been mingled here.
> Alex pointed out that decimal floating point has the same problems as
> binary as far as accuracy is concerned.

You're right. When I made my comment about floating point errors for
non-fractional numbers, I didn't made this distinction. Normally, when
I think about a money type, I don't think about floating point
decimal, I think about fixed point.

Now that we are talking about money types, I had an idea some time
ago and I would appreciate to hear some opinions. What do you think
about using a different notation for fixed point decimal literals in
Python, using the $ sign, as in:

a) $1.0000 --> fixed point decimal, four digits of precision
b) 1$0000 -> alternative syntax, also with four digits

and operations would also be easier to write, with type coercion, etc:

$1.00 + 0.99212 --> $1.99 (rounded)

That would make easy to supply fixed point literals. And I dont think
that the use of a symbol, in this case, is a case of Perlish
contamination -- even in countries where the money sign is different,
I think that most programmers would readily recognize the $ sign for
it. How about it?

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro@gmail.com
mail: carribeiro@yahoo.com


Relevant Pages

  • Re: user defined function doesnt return correct money value
    ... > Dear Dica ... > precision mean total number of decimal digits that can be stored, ... money as the data type would fix this, ... >> float) ...
    (microsoft.public.sqlserver)
  • Enigma 1483 - Almost the same digits
    ... Enigma 1483 - Almost the same digits ... Some amounts in old money can be represented ... these methods of designating that amount uses ... six digits, but with one exception, 4, the ...
    (rec.puzzles)
  • Re: Enigma 1483 - Almost the same digits
    ... shilling, each shilling being divided ... Some amounts in old money can be represented ... these methods of designating that amount uses ... digits used for the amount in old money are ...
    (rec.puzzles)
  • Re: HMDI Cable - Is there a difference in a $49 to a $250 cable
    ... > But carrying the digits to the point of analog conversion--as long as ... there's no need to spend more money on the cable. ... Prev by Date: ...
    (alt.tv.tech.hdtv)
  • Re: Duplicate Records From a Table
    ... You're right on the money with what I want. ... >>> I'm trying to find duplicates within a table where a field name called ... >>> I want the query to show me all FIVE records because they are all alike ... >>> within the first nine digits. ...
    (microsoft.public.access.queries)

Loading