{"id":5415,"date":"2024-11-14T10:01:09","date_gmt":"2024-11-14T02:01:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5415\/"},"modified":"2024-11-14T10:01:09","modified_gmt":"2024-11-14T02:01:09","slug":"mysql%e4%b8%a4%e4%bd%8d%e5%b0%8f%e6%95%b0%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5415\/","title":{"rendered":"mysql\u4e24\u4f4d\u5c0f\u6570\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  mysql\u4e2d\u8bbe\u7f6e\u4e24\u4f4d\u5c0f\u6570\u9700\u4f7f\u7528decimal\u6570\u636e\u7c7b\u578b\uff0c\u683c\u5f0f\u4e3a\uff1adecimal(\u603b\u4f4d\u6570\uff0c\u5c0f\u6570\u4f4d)\uff0c\u4f8b\u5982decimal(10, 2)\u8868\u793a\u603b\u4f4d\u657010\u4f4d\uff0c\u5c0f\u6570\u4f4d2\u4f4d\u3002\u6b65\u9aa4\u5305\u62ec\uff1a\u521b\u5efa\u8868\u5e76\u5b9a\u4e49decimal\u5217\u3001\u63d2\u5165decimal\u6570\u636e\u3001\u68c0\u7d22\u6570\u636e\uff0c\u7ed3\u679c\u5c06\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052811512236094.jpg\" class=\"aligncenter\" title=\"mysql\u4e24\u4f4d\u5c0f\u6570\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" alt=\"mysql\u4e24\u4f4d\u5c0f\u6570\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e MySQL \u4e2d\u4e24\u4f4d\u5c0f\u6570<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\u8bbe\u7f6e\u4e24\u4f4d\u5c0f\u6570\u9700\u8981\u4f7f\u7528 DECIMAL \u6570\u636e\u7c7b\u578b\u3002DECIMAL \u7528\u4e8e\u5b58\u50a8\u7cbe\u786e\u7684\u6570\u503c\uff0c\u5e76\u6307\u5b9a\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u8868\u5e76\u5b9a\u4e49\u5217\uff1a<\/strong><\/p>\n<pre>CREATE TABLE products (\n    price DECIMAL(10, 2)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>(10, 2) \u8868\u793a\u5217\u7c7b\u578b\u4e3a DECIMAL\uff0c\u603b\u4f4d\u6570\u4e3a 10 \u4f4d\uff0c\u5c0f\u6570\u4f4d\u4e3a 2 \u4f4d\u3002<\/li>\n<li>price \u662f\u5217\u540d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u63d2\u5165\u6570\u636e\uff1a<\/strong><\/p>\n<pre>INSERT INTO products (price) VALUES (123.45);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u68c0\u7d22\u6570\u636e\uff1a<\/strong><\/p>\n<pre>SELECT price FROM products;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7ed3\u679c\uff1a<\/p>\n<pre>123.45<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>DECIMAL \u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u5b58\u50a8\u5927\u4e8e 9 \u4f4d\u7684\u6570\u5b57\uff0c\u4f46\u5c0f\u6570\u4f4d\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e\u603b\u4f4d\u6570\u3002<\/li>\n<li>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cDECIMAL \u6570\u636e\u7c7b\u578b\u5b58\u50a8 0 \u4f4d\u5c0f\u6570\u3002<\/li>\n<li>\u5b58\u50a8\u7cbe\u5ea6\u8f83\u9ad8\u7684\u6570\u5b57\uff08\u4f8b\u5982\u8d27\u5e01\u503c\uff09\u65f6\uff0c\u5efa\u8bae\u4f7f\u7528 DECIMAL \u6570\u636e\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e24\u4f4d\u5c0f\u6570\u600e\u4e48\u8bbe\u7f6e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql\u4e2d\u8bbe\u7f6e\u4e24\u4f4d\u5c0f\u6570\u9700\u4f7f\u7528decimal\u6570\u636e\u7c7b\u578b\uff0c\u683c\u5f0f\u4e3a\uff1adecimal(\u603b\u4f4d\u6570\uff0c\u5c0f\u6570\u4f4d)\uff0c\u4f8b\u5982decimal(10, 2)\u8868\u793a\u603b\u4f4d\u657010\u4f4d\uff0c\u5c0f\u6570\u4f4d2\u4f4d\u3002\u6b65\u9aa4\u5305\u62ec\uff1a\u521b\u5efa\u8868\u5e76\u5b9a\u4e49decimal\u5217\u3001\u63d2\u5165decimal\u6570\u636e\u3001\u68c0\u7d22\u6570\u636e\uff0c\u7ed3\u679c\u5c06\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002 \u5982\u4f55\u8bbe\u7f6e MySQL \u4e2d\u4e24\u4f4d\u5c0f\u6570 \u5728 MySQL \u4e2d\u8bbe\u7f6e\u4e24\u4f4d\u5c0f\u6570\u9700\u8981\u4f7f\u7528 DECIMAL \u6570\u636e\u7c7b\u578b\u3002DECIMAL \u7528\u4e8e\u5b58\u50a8\u7cbe\u786e\u7684\u6570\u503c\uff0c\u5e76\u6307\u5b9a\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570\u3002 \u6b65\u9aa4\uff1a \u521b\u5efa\u8868\u5e76\u5b9a\u4e49\u5217\uff1a CREATE TABLE products ( price DECIMAL(10, 2) ); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a (10, 2) \u8868\u793a\u5217\u7c7b\u578b\u4e3a DECIMAL\uff0c\u603b\u4f4d\u6570\u4e3a 10 \u4f4d\uff0c\u5c0f\u6570\u4f4d\u4e3a 2 \u4f4d\u3002 price \u662f\u5217\u540d\u3002 \u63d2\u5165\u6570\u636e\uff1a INSERT INTO products (price) VALUES (123.45); \u767b\u5f55\u540e\u590d\u5236 \u68c0\u7d22\u6570\u636e\uff1a SELECT price FROM products; \u767b\u5f55\u540e\u590d\u5236 \u7ed3\u679c\uff1a 123.45 \u767b\u5f55\u540e\u590d\u5236 \u6ce8\u610f\uff1a DECIMAL \u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u5b58\u50a8\u5927\u4e8e 9 \u4f4d\u7684\u6570\u5b57\uff0c\u4f46\u5c0f\u6570\u4f4d\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e\u603b\u4f4d\u6570\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5415","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5415"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5415\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}