Question about floating point

Frank Millman frank at chagford.com
Tue Aug 28 10:47:25 EDT 2018


"Frank Millman"  wrote in message news:pm3l2m$kv4$1 at blaine.gmane.org...
>
> I know about this gotcha -
>
> >>> x = 1.1 + 2.2
> >>> x
> 3.3000000000000003
>
[...]
>
> >>> y = 3.3
> >>> y
> 3.3
>
[...]
>
> >>> z = (1.1 + 2.2) * 10 / 10
> >>> z
> 3.3

Thanks to Chris and Stephen for the replies.

They were interesting, but actually did not answer the question that I 
forgot to ask!

The reason for my query is this. I am assisting someone with an application 
involving monetary values. 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.

My gut-feel says that they are wrong, but I don't have the knowledge to 
prove it. I think a lot depends on what they are going to do with this value 
down the line - maybe it is 'safe enough' for their purposes, so I don't 
want to overstate my case. Are there edge cases where that rounding method 
could fail?

Frank





More information about the Python-list mailing list