[Python-Dev] Decimal data type issues (original) (raw)
Batista, Facundo FBatista at uniFON.com.ar
Wed Apr 14 17:38:26 EDT 2004
- Previous message: [Python-Dev] Decimal data type issues
- Next message: [Python-Dev] Decimal data type issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Ka-Ping Yee]
#- I agree with Tony. Having both Decimal() and #- Decimal.from_string() work #- in similar but subtly different ways seems likely to be #- misunderstood.
Decimal(string) works the way we want/need/desire. Decimal.from_string(string) works the way the documentation specify.
I think we can only change the way the former works or the name of the latter.
#- I also think his last suggestion could provide a nice, #- convenient solution #- to the conversion-from-float issue, since it raises the same #- question (a #- method named "Decimal.from_float" doesn't explain how or why #- it is different #- from just constructing with a float).
You can NOT construct directly from a float. That's the difference.
#- So here's a more detailed suggestion. Suppose s = '12345', #- f = 12.345, #- the default context specifies a precision of 9 as given in #- the PEP, and #- c is a context object with a precision of 6. #- #- Then this: would yield this: #- #- Decimal(s) Decimal((0, (1, 2, 3, 4, 5), 0)) #- ... #- Decimal(s, context=c) Decimal((0, (1, 2, 3, 4, 5, 0), -1)) #- ... #- Decimal(f) Decimal((0, (1, 2, 3, 4, 5, 0, 0, 0, 0, 0,... #- ...
The community agreed to not create directly from float. You have the from_float() method instead.
Also, remember that the context doesn't affect the creation when you create directly from string (only if you use from_string). Your example means to change the behaviour of the creation when creating directly from string? And when create directly from int or long?
#- (Do I assume correctly that there will be context objects #- that wrap up #- the precision and rounding mode, and there will be some sort #- of interface #- for getting and setting the current context?)
Yes. You can get the context with getcontext() and then change it attributes.
. Facundo
- Previous message: [Python-Dev] Decimal data type issues
- Next message: [Python-Dev] Decimal data type issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]