# [DB-SIG] Fixed point numbers (Result from DCOracle2 different from sqlplus)

Magnus Lyckå magnus@thinkware.se
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
issue...

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...

class Money:
def __init__(self, whole, fraction, currency):
self.__currency = Currency(currency)
denominator = self.__currency.centSize # Usually 100
self.__value(Rational(whole*denominator+fraction,denominator))

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...
class SEK(Money):
def __init__(self, kr, ore):
Money.__init__(self,kr,ore,'SEK')

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:
>>> 0b101
5
>>> "%b" % 5
'101'
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
>>> int('101',2)
5

But going back to the subject:

Floating point arithmetic makes sense for engineering and
they don't. It's no accident that both COBOL and relational
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
http://www.thinkware.se/  mailto:magnus@thinkware.se

```