[Tutor] Decimal fixed point representation

Kent Johnson kent37 at tds.net
Fri Nov 21 15:32:12 CET 2008


On Fri, Nov 21, 2008 at 8:22 AM, Dinesh B Vadhia
<dineshbvadhia at hotmail.com> wrote:
> Hi Alan
>
> That's right, it is the Decimal module I'm trying to understand.  And, it is
> how to represent a decimal floating point number as a common/vulgar fraction
> eg 1.234 = 1234/1000.  How do you do this using the Decimal module?  The
> motivation is to avoid floating point calculations and use integers only
> (don't ask why!).  Cheers!

The Decimal type does not represents numbers as fractions, it
represents them as decimal floating point, i.e. a floating point
representation using base 10 instead of base 2.

A fractions module was introduced in Python 2.6 that does represent
numbers as a numerator and denominator:
http://docs.python.org/library/fractions.html

Kent


More information about the Tutor mailing list