{"id":5972,"date":"2024-11-14T13:34:05","date_gmt":"2024-11-14T05:34:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5972\/"},"modified":"2024-11-14T13:34:05","modified_gmt":"2024-11-14T05:34:05","slug":"sql-round%e5%ad%97%e6%ae%b5%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5972\/","title":{"rendered":"sql\u00a0round\u5b57\u6bb5\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  sql round() \u51fd\u6570\u56db\u820d\u4e94\u5165\u6570\u5b57\u5230\u6307\u5b9a\u4f4d\u6570\u3002\u5b83\u6709\u4e24\u79cd\u7528\u6cd5\uff1a1. num_digits&gt;0\uff1a\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u4f4d\uff1b2. num_digits\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/12\/2024061203181961597.jpg\" class=\"aligncenter\" title=\"sql\u00a0round\u5b57\u6bb5\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"sql\u00a0round\u5b57\u6bb5\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL ROUND() \u51fd\u6570\u8be6\u89e3<\/strong><\/p>\n<p>SQL ROUND() \u51fd\u6570\u7528\u4e8e\u5c06\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u4f4d\u6570\u3002\u5176\u57fa\u672c\u8bed\u6cd5\u4e3a\uff1a<\/p>\n<pre>ROUND(number, num_digits)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li> <strong>number\uff1a<\/strong>\u8981\u56db\u820d\u4e94\u5165\u7684\u6570\u5b57\u3002<\/li>\n<li> <strong>num_dis\uff1a<\/strong>\u6307\u5b9a\u56db\u820d\u4e94\u5165\u7684\u4f4d\u6570\uff0c\u53ef\u4ee5\u4e3a\u8d1f\u6570\u6216\u6b63\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/p>\n<p>\u4e0b\u8868\u5c55\u793a\u4e86\u4f7f\u7528 ROUND() \u51fd\u6570\u7684\u51e0\u4e2a\u793a\u4f8b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u8f93\u5165<\/th>\n<th>num_digits<\/th>\n<th>\u8f93\u51fa<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>123.4567<\/td>\n<td>0<\/td>\n<td>123<\/td>\n<\/tr>\n<tr>\n<td>123.4567<\/td>\n<td>2<\/td>\n<td>123.46<\/td>\n<\/tr>\n<tr>\n<td>123.4567<\/td>\n<td>-1<\/td>\n<td>120<\/td>\n<\/tr>\n<tr>\n<td>123.4567<\/td>\n<td>3<\/td>\n<td>123.457<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u6b63\u8d1f num_digits \u7684\u533a\u522b<\/strong><\/p>\n<ul>\n<li> <strong>num_digits &gt; 0\uff1a<\/strong>\u5c06\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\u3002\u4f8b\u5982\uff0cROUND(123.4567, 2) \u8f93\u51fa 123.46\u3002<\/li>\n<li><strong>num_digits \u5c06\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u6574\u6570\u4f4d\u3002\u4f8b\u5982\uff0cROUND(123.4567, -1) \u8f93\u51fa 120\u3002<\/strong><\/li>\n<\/ul>\n<p><strong>\u8c28\u614e\u4f7f\u7528<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 ROUND() \u51fd\u6570\u65f6\uff0c\u8bf7\u6ce8\u610f\u4ee5\u4e0b\u4e8b\u9879\uff1a<\/p>\n<ul>\n<li>\u8be5\u51fd\u6570\u53ea\u4f5c\u7528\u4e8e\u6570\u5b57\u5b57\u6bb5\uff0c\u5bf9\u975e\u6570\u5b57\u5b57\u6bb5\u65e0\u6548\u3002<\/li>\n<li>\u5982\u679c num_digits \u4e3a 0\uff0c\u5219\u5c06\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6700\u63a5\u8fd1\u7684\u6574\u6570\u3002<\/li>\n<li>\u5982\u679c num_digits \u4e3a\u8d1f\u6570\uff0c\u5219\u5c06\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\uff0c\u76f4\u5230\u8fbe\u5230\u6574\u6570\u3002<\/li>\n<li>\u8be5\u51fd\u6570\u4e0d\u4f1a\u6539\u53d8\u539f\u59cb\u6570\u5b57\uff0c\u53ea\u4f1a\u8fd4\u56de\u56db\u820d\u4e94\u5165\u540e\u7684\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql&nbsp;round\u5b57\u6bb5\u600e\u4e48\u7528\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>sql round() \u51fd\u6570\u56db\u820d\u4e94\u5165\u6570\u5b57\u5230\u6307\u5b9a\u4f4d\u6570\u3002\u5b83\u6709\u4e24\u79cd\u7528\u6cd5\uff1a1. num_digits&gt;0\uff1a\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u4f4d\uff1b2. num_digits SQL ROUND() \u51fd\u6570\u8be6\u89e3 SQL ROUND() \u51fd\u6570\u7528\u4e8e\u5c06\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u4f4d\u6570\u3002\u5176\u57fa\u672c\u8bed\u6cd5\u4e3a\uff1a ROUND(number, num_digits) \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a number\uff1a\u8981\u56db\u820d\u4e94\u5165\u7684\u6570\u5b57\u3002 num_dis\uff1a\u6307\u5b9a\u56db\u820d\u4e94\u5165\u7684\u4f4d\u6570\uff0c\u53ef\u4ee5\u4e3a\u8d1f\u6570\u6216\u6b63\u6570\u3002 \u4f7f\u7528\u793a\u4f8b \u4e0b\u8868\u5c55\u793a\u4e86\u4f7f\u7528 ROUND() \u51fd\u6570\u7684\u51e0\u4e2a\u793a\u4f8b\uff1a \u8f93\u5165 num_digits \u8f93\u51fa 123.4567 0 123 123.4567 2 123.46 123.4567 -1 120 123.4567 3 123.457 \u6b63\u8d1f num_digits \u7684\u533a\u522b num_digits &gt; 0\uff1a\u5c06\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\u3002\u4f8b\u5982\uff0cROUND(123.4567, 2) \u8f93\u51fa 123.46\u3002 num_digits \u5c06\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u6574\u6570\u4f4d\u3002\u4f8b\u5982\uff0cROUND(123.4567, -1) \u8f93\u51fa 120\u3002 \u8c28\u614e\u4f7f\u7528 \u5728\u4f7f\u7528 ROUND() \u51fd\u6570\u65f6\uff0c\u8bf7\u6ce8\u610f\u4ee5\u4e0b\u4e8b\u9879\uff1a \u8be5\u51fd\u6570\u53ea\u4f5c\u7528\u4e8e\u6570\u5b57\u5b57\u6bb5\uff0c\u5bf9\u975e\u6570\u5b57\u5b57\u6bb5\u65e0\u6548\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-5972","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5972","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=5972"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5972\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}