osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about floating point


On Wed, 29 Aug 2018 11:31:29 +1200, Gregory Ewing wrote:

> Frank Millman wrote:
>> I have been trying to explain why
>> they should use the decimal module. They have had a counter-argument
>> from someone else who says they should just use the rounding technique
>> in my third example above.
> 
> It's possible to get away with this by judicious use of rounding.
> There's a business software package I work with that does this -- every
> number is rounded to a defined number of decimal places before being
> stored in its database, so the small inaccuracies resulting from inexact
> representations don't get a chance to accumulate.

This software package doesn't actually use the *10/10 trick, does it?

As an answer to the question, "Should I use this clever *10/10 trick?" 
I'm not sure it's relevant to say "Yep, sure, this package does something 
completely different and it works fine!" *wink*

> If you're going to do this, I would NOT recommend using the rounding
> technique in your example -- it seems to itself be relying on accidents
> of the arithmetic. Use the round() function:

Or better still, DON'T manually use the round function, let the 
interpreter do the rounding for you by using Decimal. That's what its for.

Why in the name of all that's holy would anyone want to manually round 
each and every intermediate calculation when they could use the Decimal 
module and have it do it automatically?



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson