[DB-SIG] Fixed point numbers (Result from DCOracle2
different from sqlplus)
Fri, 16 Nov 2001 14:45:39 +0100
At 10:46 2001-11-16 +0100, M.-A. Lemburg wrote:
>How strong is the need for a fixed point data type ?
Maybe I should say something since I raised the
I don't have a strong need right now. When I've been
cursing my commercial accounting software for its
stupidity (and no other package I've seen seem to
address the basic flaws), I've often thought that I
should do something better in Python, or at least a
front end so that I can work more conveniently.
If I ever get irritated enough to actually do that,
I would probably need some kind of money class. As
M.-A. pointed out, this is easily sovled with a long
and an int. Although, using a rational numbers class
is also a solution. With a Rational(n,d) class I could
imagine something like...
def __init__(self, whole, fraction, currency):
self.__currency = Currency(currency)
denominator = self.__currency.centSize # Usually 100
def __add__(self, other):
assert self.__currency == other.__currency
val = self.__value + other.__value
whole, frac = val.divmod()
return Money(whole, frac, self.__currency)
I guess I'd use the following for a few more years...
def __init__(self, kr, ore):
Actually, I have a backlog of book keeping. Maybe this
could be a way do make all that boring book keeping fun!
From the db-sig point of view, a fixed point numbers
class would certainly provide a better match to the
databases, since they all provide this type.
Then we just need to get a DateTime package and support
for bit strings into the standard library and we're all
set! Right? (Well, I don't know how compatible we are
with SQL in National Character handling...)
I guess good support for bit (strings) should be:
>>> "%b" % 5
Considering the discussion of Python for learning programming
and the importance of binary nubers in actually understanding
how computers work, I think this is an oversight.
At least we have
But going back to the subject:
Floating point arithmetic makes sense for engineering and
scientific computations. For areas like business administration
they don't. It's no accident that both COBOL and relational
databases that are often used for business administration etc,
support fixed point numbers.
If Python is (as I gather) intended for a wide audience, and
supposed to be useful also for people who are not professional
programmers, I think support for fixed point arithmetic would
be a Good Thing.
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel 070-582 80 65, fax: 070-612 80 65