mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
Issue 8257: Decimal constructor to accept float.
This commit is contained in:
parent
dc36d7cf85
commit
ed171abd93
3 changed files with 45 additions and 11 deletions
|
@ -648,8 +648,12 @@ class Decimal(object):
|
|||
return self
|
||||
|
||||
if isinstance(value, float):
|
||||
raise TypeError("Cannot convert float in Decimal constructor. "
|
||||
"Use from_float class method.")
|
||||
value = Decimal.from_float(value)
|
||||
self._exp = value._exp
|
||||
self._sign = value._sign
|
||||
self._int = value._int
|
||||
self._is_special = value._is_special
|
||||
return self
|
||||
|
||||
raise TypeError("Cannot convert %r to Decimal" % value)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue