我将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
答案 0 :(得分:0)
这并不意味着Python在小数点后丢失了数字的位数。如果您只需要打印2位小数,那么您应该查看this question的答案。即:
'%.2f' % your_number