Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取数据时如何保留mysql格式_Python_Mysql - Fatal编程技术网

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