我正在尝试使用python和sql查询将数据插入数据库。我只想插入小数点后两位以内的数据。那我该怎么办?我的代码:
mycursor.execute("INSERT INTO DHT_sensor VALUES (%s,%s,%s)",(i,temperature,humidity))
watbbzwu1#
i,temperature,humidity = 12.2345, 14.5653442, 4346.345363 q = "INSERT INTO DHT_sensor VALUES (%.2f,%.2f,%.2f)"%(i,temperature,humidity) print(q) # INSERT INTO DHT_sensor VALUES (12.23,14.57,4346.35) mycursor.execute(q)
1条答案
按热度按时间watbbzwu1#