np.float64与本机Python float的str表示形式的差异

时间:2018-12-13 16:22:53

标签: python numpy

在原生Python try: mydb = mysql.connector.connect( host="localhost", user="root", password="123456", database="v21") c = mydb.cursor() lat = 36.8451995849609 lng = 54.428798675537 city = "Rasht" state = "Gilan" user = 70440675 arg = (user, state, city, lat, lng) c.callproc('do1', arg) mydb.commit() except mysql.connector.Error as err: print("Something went wrong: {}".format(err)) 类型中,将float强制转换为float时似乎没有舍入:

str

但是,当将In [1]: foo = 0.24000000000000002 In [2]: print(str(foo)) 0.24000000000000002 In [3]: print(repr(foo)) 0.24000000000000002 强制转换为np.float64时,会出现四舍五入的情况。

str

In [4]: print(str(np.float64(foo))) 0.24 In [5]: print(repr(np.float64(foo))) 0.24000000000000002 强制转换为np.float64时,舍入的逻辑是什么?

0 个答案:

没有答案