[Python-Dev] Re: Decimal data type issues (original) (raw)
Kevin Jacobs jacobs at theopalgroup.com
Tue Apr 20 08:04:16 EDT 2004
- Previous message: [Python-Dev] Re: Decimal data type issues
- Next message: [Python-Dev] PEP 329: Treating Builtins as Constants inthe Standard Library
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Batista, Facundo wrote:
[Jewett, Jim J] #- 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.
It is posible:
Decimal('2.4000')
Decimal( (0, (2, 4, 0, 0, 0), -4) ) Decimal('2.4') Decimal( (0, (2, 4), -1) )
Great!. One of my previous posts specifically listed that I didn't want to have to pre-parse and reformulate string literals to achieve the desired precision and scale. The "external" library solution will either have to do that, or create a Decimal from the string literal, look at the tuple length and exponent and form a new Decimal instance, rounding if necessary. Hmmm... sounds like something low-level enough that Decimal should be doing it. And remember, SQL and many financial applications will be doing this operation for every datum they load.
#- 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.
If you construct using precision, and the precision is smaller than the quantity of digits you provide, you'll get rounded, but if the precision is greater than the quantity of digits you provide, you don't get filled with zeros.
Rounding is exactly what should be done if one exceeds the desired precision. Using less that the desired precision (i.e., not filling in zeros) may be okay for many applications. This is because any operations on the value will have to be performed with the precision defined in the decimal context. Thus, the results will be identical, other than that the Decimal instance may not store the maximum precision available by the schema.
Thanks, -Kevin
- Previous message: [Python-Dev] Re: Decimal data type issues
- Next message: [Python-Dev] PEP 329: Treating Builtins as Constants inthe Standard Library
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]