[issue14262] Allow using decimals as arguments to `timedelta`

Alexander Belopolsky report at bugs.python.org
Thu Sep 20 00:38:02 CEST 2012


Alexander Belopolsky added the comment:

On Sep 19, 2012, at 5:36 PM, Ram Rachum <report at bugs.python.org> wrote:

> Why would we use float to represent the ratio of the bonus to the client?

Because float is the builtin type that Python provides to represent such quantities. 

> Why would we risk imprecision there when Decimal provides us with perfect precision?

Python float is a much simpler and more efficient type than Decimal.  One should have a really good reason to introduce Decimal in the program.  In case of money, Decimal provides a *lower* precision alternative to float together with the control over rounding direction.  This is important in applications where fractions of a penny have to be dealt with in very precise manner. 

In your application, float is a perfectly good type to represent 15% bonus.  Even if your customers insist on microsecond precision, float is good enough and timedelta resolution will prevent you from supporting higher precision anyways. 

As I mentioned before, I would be happy to see greater interoperability between numerical types in Python and interoperability between timedelta and Decimal may come as a side benefit of that effort.  However, I don't find your use case to be compelling enough to either justify special case code or to motivate a more general effort.

----------

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


More information about the Python-bugs-list mailing list