Re: [Tutor] Decimal fixed point representation
On Fri, Nov 21, 2008, Dinesh B Vadhia wrote: > > 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! I can understand why if one is writing accounting applications that have to be accurate to the penny (or whatever in the local currency). Accountants and auditors don't like rounding errors. The accounting system I wrote in the mid-80s, and still use today, is written mostly in C, and handles all monitary calculations in cents in long integers with appropriate input and output routines to make them look to the world as it would expect. There was (is?) a FixedPoint package in python that I use for handling dollar amounts. It came out before the Decimal type, and I am not fixing something that works. The only machines I worked on extensively that handled decimal arithmatic very well were the Burroughs Medium Systems B-2500 through B-4800 which did everything in decimal which made a lot of sense since they were designed primarily to run COBOL accounting applications. Bill -- INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way Voice: (206) 236-1676 Mercer Island, WA 98040-0820 Fax:(206) 232-9186 Scientists are explorers. Philosophers are tourists. -- Richard Feynman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Decimal fixed point representation
On Fri, Nov 21, 2008 at 8:22 AM, Dinesh B Vadhia <[EMAIL PROTECTED]> 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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Decimal fixed point representation
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 - From: "Alan Gauld" <[EMAIL PROTECTED]> Subject: Re: [Tutor] Decimal fixed point representation To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Dinesh B Vadhia" <[EMAIL PROTECTED]> 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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Decimal fixed point representation
"Dinesh B Vadhia" <[EMAIL PROTECTED]> 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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Decimal fixed point representation
Dinesh B Vadhia 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). Huh? That makes no sense to me! Examples please. -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor