Python 获取数据时如何保留mysql格式
我将Python 获取数据时如何保留mysql格式,python,mysql,Python,Mysql,我将customer\u 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 这并不意味着Python正在丢失小数点后的数字。如果你只需要用小数点后2位打印出来,那么你应该看看答案。即
customer\u 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
这并不意味着Python正在丢失小数点后的数字。如果你只需要用小数点后2位打印出来,那么你应该看看答案。即:
'%.2f' % your_number