[Tutor] Decimal fixed point representation

Dinesh B Vadhia dineshbvadhia at hotmail.com
Fri Nov 21 14:22:22 CET 2008


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!

Dinesh



--------------------------------------------------------------------------------
Date: Fri, 21 Nov 2008 01:03:05 -0000
From: "Alan Gauld" <alan.gauld at btinternet.com>
Subject: Re: [Tutor] Decimal fixed point representation
To: tutor at python.org
Message-ID: <gg51ca$ud6$1 at ger.gmane.org>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original


"Dinesh B Vadhia" <dineshbvadhia at hotmail.com> wrote 

> I'm trying to get my head around the Decimal module to 
> understand how to represent a decimal floating point 
> number as an integer (or integers).  

I'm not sure what you mean by that.

Is it the use of the Decimal module you are querying?

Is it how to represent a ecimal fraction as an 
integer - ie how to lose the numbers after the point?

Is it how to represent it as a common/vulgar fraction
eg 1.234 = 1234/1000

Or something else?

> Am I barking mad or is this possible?

It is possible that you are barking mad I suppose. 

As to whether what you are asking about decimals 
is possible, that depends on what you are actually 
asking :-)

Alan G

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081121/8b63ab74/attachment.htm>


More information about the Tutor mailing list