python - 如何使用python将数据插入到只有两位小数的表中?

标签 python mysql

我正在尝试使用 python 和 SQL 查询将数据插入数据库。 我只想插入小数点后两位的数据。那我该怎么办?

我的代码:

mycursor.execute("INSERT INTO DHT_sensor VALUES (%s,%s,%s)",(i,temperature,humidity))

最佳答案

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)

关于python - 如何使用python将数据插入到只有两位小数的表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53975998/

相关文章:

python - Django 重复条目 1062

mysql - 我有一个类似于以下的表格。我想要不同状态的单独计数

Mysql FK : Who should be the parent and who should be the children in the above situation

python "' NoneType'对象没有属性 'encode'“

python - 将 TXT 加载到 postgres 数据库中,将不存在的列填充为 null

python - 如果前一行有感知变化,则替换值数据框列值

Mysql 列和速度的限制

mysql - Delphi Rave Report 生成空白页

python - pycurl.INFOTYPE_HEADER_OUT 有什么用?

python - 如何计算多标签分类中的 F1 度量?