[Python-Dev] Re: Decimal data type issues

Jewett, Jim J jim.jewett at eds.com
Mon Apr 19 15:46:31 EDT 2004

On Mon, Apr 19, 2004, Jewett, Jim J wrote:

> [Kevin Jacobs]
> #-   Decimal('2.4000', precision=2, scale=1) == Decimal('2.4')
> #-   Decimal('2.4', precision=5, scale=4) == Decimal('2.4000')
> #- 
> #- Remember, these literals are frequently coming from an 
> #- external source that must be constrained to a given schema.
> Facundo
>> I like it a lot, but not for Decimal.
> This is another face of "what do do with float"

> This has nothing to do with binary floating point.  These are 
> strings that map to exact numbers in Decimal; 

Under the current implementation:

	(0, (2, 4, 0, 0, 0), -4) 

is not quite the same as

	(0, (2, 4) -1)

Given this, is should be possible for the user to specify 
(at creation) which is desired.

They do normalize to the same thing, but this requires 
extending the second number with zeros.

	(0, (1,), -17)	
	(0, (1, 1), -1)

The float discussions make it clear that "extend by zero"
may not always be the most accurate, and the python docs
do not yet prohibit extending by some other digit (that
rounds the same).

I agree that the programmer should specify if they want 
something odd -- and that is precisely why the constructor 
should take an optional context argument which allows the 
user to specify precision.

Given that float input may well look like string (saved to a
file by another program) or even an integer (C double may have 
more precision than C long) there is no particular reason to
say "context is only allowed when constructing from a float"


More information about the Python-Dev mailing list