Re: [Modeling-users] Money and Modeling
Status: Abandoned
Brought to you by:
sbigaret
From: Yannick G. <ygi...@yg...> - 2003-07-08 22:25:49
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 08 July 2003 17:19, you wrote: > Fixed point doesn't exist in the default python so . You always retrieve > a numeric but it's map to > a float in python. And please be carefull about this as, python do some > strange round while > using print() and stuff like that . I got a quick explain here in my > bookmark but it's in french . > > >>> 6+1 > 7 this is a integer > >>> 6.0 + 1 > 7.0 this is a float > > >>> print "%s" % ( 6.0 + 1) > 7.0 > >>> print "%d" % ( 6.0 + 1) > 7 Argh ! >>> val = 1.1 >>> val 1.1000000000000001 I just created a small amount of money from nowhere. A really small one but imprecision of floats adds up and financial controllers really hate when some money appears from nowhere... >>> 45.678 45.677999999999997 I just lost a small amount of money in the deep void. A really small one but... How about : class FixedPoint: def __init__(self): self._val = 0 # int self._pointPos = 0 # int too With a few operators overloaded it would map nicely with the SQL decimal and could easily serialize to a simple tuple (like mx.DateTime.tuple()) If it make sense I can send a sketchy class that could be shipped with Modeling. - -- Yannick Gingras Coder for OBB : Omniscient Behaviouristic Baroque http://OpenBeatBox.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE/CtAqrhy5Fqn/MRARAqNyAJ9w3WxZSYiJpQDO1lbWtFSLexBZxwCfWr4T b96i1XQ5ozrPY8N7UmSn6l4= =Q7Uf -----END PGP SIGNATURE----- |