[Python-Dev] Re: Decimal data type issues (original) (raw)
Batista, Facundo FBatista at uniFON.com.ar
Wed Apr 21 16:03:35 EDT 2004
- Previous message: [Python-Dev] peps 329, 266, 267
- Next message: [Python-Dev] Re: Decimal data type issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Tim Peters]
#- [Batista, Facundo] #- > ... #- > - Methods like round() don't need to be discussed: the #- Spec defines #- > how them work, and the PEP is for implementing the PEP. #- #- Actually, there is no round() operation in the spec. I #- don't remember #- whether there used to be, but there definitely isn't now.
You're right. My fault.
#- Doesn't mean we #- can't supply .round(), does mean we have to spell out what #- it does. I #- assume decimal.round(whatever) acts the same as the spec's #- decimal.plus() #- would act if "whatever" were temporarily (for the duration #- of plus()) folded #- into context. If so, that's all it needs to say.
Well, I think we must decide how it works
With:
d = Decimal('12345.678') d Decimal( (0, (1, 2, 3, 4, 5, 6, 7, 8), -3) ) str(d) '12345.678'
And being the syntax Decimal.round(n), we have the following options:
a) n is the quantity of relevant digits of the final number (must be non negative).
>>> d.round(4)
Decimal( (0, (1, 2, 3, 5), 1L) )
>>> str(d.round(4))
'1.235E+4'
b) n has the same behaviour that in the built in round().
>>> d.round(1)
Decimal( (0, (1, 2, 3, 4, 5, 7), -1L) )
>>> str(d.round(1))
'12345.7'
>>> d.round(-1)
Decimal( (0, (1, 2, 3, 5), 1L) )
>>> str(d.round(-1))
'1.235E+4'
What option do you all like more?
. Facundo
- Previous message: [Python-Dev] peps 329, 266, 267
- Next message: [Python-Dev] Re: Decimal data type issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]