如何在获取数据时保留mysql格式

时间:2012-05-08 20:29:26

标签: python mysql

我将customer_price存储为DECIMAL (8,2)

使用Python,我如何保留小数点后的两位数?

cursor.execute("SELECT customer_price FROM table")
customer_price = cursor.fetchone() # this will give me values such as 7 instead of 7.00

1 个答案:

答案 0 :(得分:0)

这并不意味着Python在小数点后丢失了数字的位数。如果您只需要打印2位小数,那么您应该查看this question的答案。即:

'%.2f' % your_number