New submission from Mark Dickinson <[email protected]>:
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 <[email protected]>
<http://bugs.python.org/issue8294>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com