convert user input to Decimal objects using eval()?

Swaroop C H swaroopch at gmail.com
Mon Mar 28 16:05:40 EST 2005


On Mon, 28 Mar 2005 12:03:24 -0500, Julian Hernandez Gomez
<jhernandez at pragma.com.co> wrote:
> is there a "easy way" to make eval() convert all floating numbers to Decimal
> objects and return a Decimal?
> eval('1.00000001+0.1111111') --> convert each number to a Decimal object,
> perform the sum and obtain a Decimal object as a result?
> maybe a parser is needed, but eval() already do the job, but I need the
> precision that Decimal offers for numerical applications.

If you need the precision, why are you using strings instead of the
numbers directly?

Also, why not simply use Decimal('1.0000000') + Decimal('0.1111111') ?

-- 
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info



More information about the Python-list mailing list