Can anyone offer a suggestion?

Roman Suzi rnd at onego.ru
Thu Jul 12 13:31:44 EDT 2001


On Thu, 12 Jul 2001, Emile van Sebille wrote:

>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
>+++++++++++++++++++++??????!

What about putting parens around ab*cb?

print '%8.2f' % (ab*cb)

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


Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Thursday, July 12, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Misfortune: The kind of fortune that never misses." _/





More information about the Python-list mailing list