[issue8294] Allow Fraction constructor to accept float and decimal instances directly.

Mark Dickinson report at bugs.python.org
Fri Apr 2 22:42:43 CEST 2010


New submission from Mark Dickinson <dickinsm at gmail.com>:

Here's a patch that allows direct construction of a Fraction instance from a float or Decimal instance, performing an exact conversion in either case.

>>> from fractions import Fraction
>>> from decimal import Decimal
>>> Fraction(1.1)
Fraction(2476979795053773, 2251799813685248)
>>> Fraction(Decimal('1.1'))
Fraction(11, 10)
>>> Fraction(Decimal(1.1))
Fraction(2476979795053773, 2251799813685248)

----------
assignee: rhettinger
components: Library (Lib)
files: fraction_from_float.patch
keywords: patch
messages: 102198
nosy: mark.dickinson, rhettinger
severity: normal
status: open
title: Allow Fraction constructor to accept float and decimal instances directly.
type: feature request
versions: Python 2.7, Python 3.2
Added file: http://bugs.python.org/file16738/fraction_from_float.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8294>
_______________________________________


More information about the Python-bugs-list mailing list