[Python-Dev] Decimal data type issues

Batista, Facundo FBatista at uniFON.com.ar
Fri Apr 16 08:48:34 EDT 2004


[Ka-Ping Yee]

#- 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 think is deeper than that. For example, *I* don't understand what is
"exact conversion" to you:

  1.1 -> "1.1"
  1.1 -> "1.1000000000000001"
  1.1 -> "1.100000000000000088817841970012523233890533447265625"

So, what is the expectation that floating point newbies will understand this
safely enough as to let them create from:

  Decimal(float, extra_argument)
  Decimal.exact_float()

To me, is complicate the things to much for the newcomer. I think the
following reasoning is simpler:

  Do you want to create from string? Strings are exact, use Decimal(string)
  Do you want to create from int/long? Ints and longs are exact, use
Decimal(int/long)
  Do you want to create from float? Oops, floats are NOT exact, so you have
to use Decimal.from_float(float), but take note of this, this and this.

.	Facundo



More information about the Python-Dev mailing list