How can i have rounded floating point numbers to be of equal values (so that ==
returns True
) no matter what operations get applied on them (i want the end rounded results to be the same float). I have the following function:
def _round(f, n):
x = f * pow(10, n)
return truediv(int(x), pow(10, n))
but it still doesn't give me the same floating number. Is there a way to make a float (no matter how it has been calculated) to look always strictly the same, since they are being used in a dictionary as keys and any small change results in a KeyError
.