Can anyone offer a suggestion?

Emile van Sebille emile at fenx.com
Thu Jul 12 11:42:35 EDT 2001


I've been writing a business math class that allows for multiple precision
accuracy, and in testing stumbled on this behavior:

>>> from BNum import BNum as bn

>>> ab = bn('1.2340000')
>>> cb = bn('123.45')
>>> ab
1.2340000
>>> ab * cb
152.3373000
>>> (ab*cb).disp(2)
'152.34'
>>> print '%8.2f' % ab*cb
151.84
+++++++++++++++++++++??????!
>>> print 1.234 * 123.45
152.3373
>>> print ab*cb
152.3373000
>>> print float(ab*cb)
152.3373
>>> print '%8.2f' % float(ab*cb)
  152.34
>>> print '%8.2f' % ab*cb
151.84
>>> print str(ab*cb)
152.3373000

How is the argument being coerced for inclusion?  I would have thought
float(), but apparently not.

Any hints appreciated.  (Otherwise I'll have to try to find it in the
source!  ;-0)


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list