Python number comparison is not equal problem

CSDN Q&A 2022-08-06 19:02:39 阅读数:920

pythonnumbercomparisonequalproblem
Phenomena and background of the problem

I use python3.9 socket, Windows system, utf-8 to send floating point and integer strings from client to server.
On the client side, I use to_string() method to send floats and integers after strings.
On the server side, I extract floating-point numbers and integers from string parsing, and keep comparing them to see if there are any duplicates. If there are no duplicates, add them to a list.

Why sometimes two floating-point numbers or integers that are equal to the naked eye are not equal using '=='?How can I solve this problem?

# client def to_string(self): return f"price,{self.__price},type,{self.__type},volume,{self.__volume}"# server if price == value: return Ture
版权声明:本文为[CSDN Q&A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2022/218/202207310344169088.html