A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-August/067883.html below:

[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers) [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)Greg Ewing greg.ewing at canterbury.ac.nz
Wed Aug 2 03:02:49 CEST 2006
M.-A. Lemburg wrote:

> You often have a need for controlled rounding when doing
> financial calculations 

You should NOT be using binary floats for money
in the first place.

 > or in situations where you want to
 > compare two floats with a given accuracy,

Pseudo-rounding to decimal places is not
the right way to do that. The right way is
to compare the difference to a tolerance.

> e.g. to work
> around rounding problems ;-)

As Tim Peters has pointed out many times,
you can't fix binary/decimal representation
problems by rounding. There are always cases
that give a different result than you would
want.

> Hmm, looks like a YAGNI to me,

In all my programming so far I've found
numerous uses for round-to-int, and exactly
zero uses for round-binary-float-to-decimal-
places. So from my point of view, the YAGNI
applies to the *current* behavour of round()!

--
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4