[Python-Dev] Decimal data type issues (original) (raw)

Ka-Ping Yee python-dev at zesty.ca
Fri Apr 16 04:58:26 EDT 2004


On Fri, 16 Apr 2004, Greg Ewing wrote:

Ka-Ping Yee <python-dev at zesty.ca>: > The extra method should be specifically for the exceptional case, > and named appropriately. > > Decimal.exactfloat(value)

That's a confusing name, since it seems to be promising that the conversion will be exact. While this might technically be true for certain values of float, there's no way the implementation can know whether the result is exactly what the user had in mind for the meaning of that float.

I think you have misunderstood my suggestion. The name promises that the conversion will be exact precisely because it is exact. The exact_float() method would always yield a Decimal number with the exact value of the given floating-point number.

My understanding of the reason for disallowing a float argument to the Decimal constructor is that people may be confused by exact conversion: they don't realize that the exact value may be slightly different from the decimal number they entered.

My point is that since exact conversion is the confusing case, that's what the special method should be for.

I'm arguing very much along the same lines as Tim: let's have an optional argument to the Decimal constructor that specifies the precision of the newly constructed Decimal value. Tim is talking about strings; i am generalizing and saying that, when the precision is specified, all number types should be accepted.

-- ?!ng



More information about the Python-Dev mailing list