[Tutor] decimal precision in python

Modulok modulok at gmail.com
Mon Feb 6 17:17:40 CET 2012


For money, you should probably use the builtin module 'decimal' instead:

http://docs.python.org/library/decimal.html

There's also the third party module 'mpmath' which provides arbitrary precision
floating point arithmetic.

http://mpmath.googlecode.com/svn/trunk/doc/build/index.html

-Modulok-

On 2/6/12, Kapil Shukla <shukla.kapil at gmail.com> wrote:
> i tried writing a small code to calculate option price using the binomial
> tree model. I compared my results with results of the same program in
> excel. There seems to be a minor difference due to decimal precision as
> excel is using 15 decimal precision and python (both 2.7 and 3.1) using 11.
> (at least that's what shown on shell)
>
> can some one guide me whats the equivalent of using a double datatype on
> python and i can't use long() in 3.1 any more.
>
> Please also suggest a free editor for python which can at least repeat
> previous command with a key stroke
>
> regards
> kapil
>


More information about the Tutor mailing list