{"id":132,"date":"2008-11-01T23:32:00","date_gmt":"2008-11-01T03:32:00","guid":{"rendered":""},"modified":"2013-11-24T21:29:06","modified_gmt":"2013-11-24T13:29:06","slug":"%e6%a0%bc%e5%bc%8f%e5%8c%96%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%87%bd%e6%95%b0format","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/132.html","title":{"rendered":"\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u51fd\u6570Format"},"content":{"rendered":"<p>function Format(const Format: string; const Args: array of const): string;<\/p>\n<p>Format\u5b57\u7b26\u4e32\u8bf4\u660e\uff1a<br \/>\n&#8220;%&#8221; [index &#8220;:&#8221;] [&#8220;-&#8220;] [width] [&#8220;.&#8221; prec] type<br \/>\n(1) \u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5fc5\u987b\u4ee5%\u5f00\u5934<br \/>\n(2) [index &#8220;:&#8221;] \u7d22\u5f15\u6307\u7684\u662fArgs\u53c2\u6570\u5217\u8868\u4e2d\u8981\u663e\u793a\u7684\u6bcf\u4e00\u9879\u7684\u5e8f\u53f7\u3002\u6bd4\u5982\uff1aArgs\u662f [&#8216;a&#8217;, &#8216;c&#8217;]\uff0c\u90a3\u4e48&#8217;a&#8217;\u7684\u7d22\u5f15\u5c31\u662f0\uff0c\u800c&#8217;c&#8217;\u7684\u7d22\u5f15\u5c31\u662f1\uff0c\u800c\u4e14\u7531\u4e8e\u53ea\u6709\u4e24\u9879\uff0c\u6240\u4ee5\u5c31\u4e0d\u4f1a\u51fa\u73b0\u5927\u4e8e1\u7684\u7d22\u5f15\u503c\u3002 Format(&#8216;%2:s %1:s %0:s&#8217;, [&#8216;1st&#8217;, &#8216;2nd&#8217;, &#8216;3rd&#8217;]); \u7ed3\u679c\uff1a&#8217;3rd 2nd 1st&#8217;<br \/>\n(3) [&#8220;-&#8220;] \u8fd9\u4e2a\u6807\u8bc6\u7b26\u7684\u4f5c\u7528\u662f\u5f53\u8981\u663e\u793a\u7684\u5b57\u7b26\u7684\u4e2a\u6570\u5c11\u4e8e[width]\u65f6\uff0c\u5728\u53f3\u8fb9\u586b\u8865\u7a7a\u683c\uff1b \u5982\u679c\u6ca1\u52a0\u4e0a[&#8220;-&#8220;]\uff0c\u5219\u5728\u5de6\u8fb9\u586b\u8865\u7a7a\u683c\u3002 Format(&#8216;(%4s)&#8217;, [&#8216;aa&#8217;]); \u7ed3\u679c\uff1a&#8217; aa&#8217;<br \/>\n(4) [width] \u5bbd\u5ea6<br \/>\n\u89c4\u5b9a\u4e86\u8981\u663e\u793a\u7684\u5b57\u7b26\u7684\u4e2a\u6570\u3002\u5982\u679c\u8981\u663e\u793a\u7684\u5bbd\u5ea6\u5927\u4e8e[width]\uff0c\u5219\u6309\u5b9e\u9645\u7684 \u5bbd\u5ea6\u6765\u663e\u793a\uff1b\u53cd\u4e4b\uff0c\u5219\u586b\u8865\u7a7a\u683c\u6216\u6309\u8981\u6c42\u586b\u8865\u5176\u5b83\u5b57\u7b26\u3002<br \/>\n(5) [&#8220;.&#8221; prec] \u7cbe\u5ea6<br \/>\n\u8fd9\u662f\u9488\u5bf9\u6d6e\u70b9\u6570\u6765\u8bf4\u7684\uff0c\u4e00\u822c\u5c31\u662f\u6307\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570\u3002<br \/>\n(6) type \u7c7b\u578b(\u89c1\u4e0b\u9762)<\/p>\n<p>type\u7684\u53ef\u80fd\u503c\u6709\u4e0b\u5217\u8fd9\u4e9b\uff1a<br \/>\n(1) d \u6709\u7b26\u53f7\u5341\u8fdb\u5236\u6570<br \/>\nArgs\u5fc5\u987b\u662f\u6709\u7b26\u53f7\u6574\u578b\u6570\u3002\u5982\u679c\u5728\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u4e2d\u8fd8\u52a0\u5165\u4e86[&#8220;.&#8221; prec]\uff0c\u5219\u5982\u679cArgs\u7684\u957f\u5ea6\u5982\u679c\u5c0f\u4e8e\u7ed9\u51fa\u7684\u7cbe\u5ea6\u6570\u65f6\uff0c\u5728\u524d\u8fb9\u586b\u88650\uff1b\u5982\u679c\u5927\u4e8e\u7cbe\u5ea6\u6570\uff0c\u6309\u5b9e\u9645\u957f\u5ea6\u663e\u793a\u3002 Format(&#8216;(%.3d)&#8217;, [99]); \u7ed3\u679c\uff1a'(099)&#8217;<\/p>\n<p>(2) u \u65e0\u7b26\u53f7\u5341\u8fdb\u5236\u6570<br \/>\nArgs\u5fc5\u987b\u662f\u65e0\u7b26\u53f7\u6574\u578b\u6570\u3002\u5176\u5b83\u7279\u6027\u4e0ed\u4e00\u6837\u3002<\/p>\n<p>(3) e \u79d1\u5b66\u6280\u672f\u6cd5<br \/>\n\u7528\u79d1\u5b66\u6280\u672f\u6cd5\u663e\u793a\u6570\u636e\uff0c\u5f62\u5f0f\u5927\u81f4\u5982\u4e0b\uff1a&#8217;-d.ddd&#8230;E+ddd&#8217;\u3002 Args\u5fc5\u987b\u662f\u4e00\u4e2a\u6d6e\u70b9\u6570\u3002\u5982\u679c\u662f\u4e00\u4e2a\u8d1f\u6570\uff0c\u5219\u5728\u6700\u524d\u9762\u663e\u793a\u4e00\u4e2a\u7b26\u53f7\uff1b\u5728\u5c0f\u6570\u70b9\u524d\u9762 \u603b\u662f\u663e\u793a\u4e00\u4f4d\u6570\u5b57\uff1b\u5305\u62ec\u5c0f\u6570\u70b9\u524d\u9762\u7684\u6570\u5b57\u5728\u5185\uff0c\u6570\u5b57\u7684\u4e2a\u6570\u7531[&#8220;.&#8221; prec]\u6765\u786e\u5b9a\uff0c \u5982\u679c\u6ca1\u6709\u6307\u5b9a[&#8220;.&#8221; prec]\uff0c\u5219\u9ed8\u8ba4\u4e3a15\u4f4d\u7cbe\u5ea6\u3002\u5982\u679c\u5b9e\u9645\u7684\u6570\u5b57\u957f\u5ea6\u8d85\u51fa\u4e86\u6307\u5b9a\u7684\u00a0\u00a0 [&#8220;.&#8221; prec]\uff0c\u5219\u521a\u521a\u8d85\u51fa\u7684\u90a3\u4e00\u4f4d\u6570\u5b57\u56db\u820d\u4e94\u5165\u3002\u6307\u6570\u7b26\u53f7E\u540e\u9762\u603b\u662f\u8981\u8ddf\u7740\u52a0\u53f7\u6216 \u51cf\u53f7\uff0c\u5e76\u4e14\u5728\u540e\u9762\u81f3\u5c11\u8ddf\u7740\u4e09\u4f4d\u6570\u5b57\u3002<\/p>\n<p>(4) f \u56fa\u5b9a\u7684<br \/>\nArgs\u5fc5\u987b\u4e3a\u6d6e\u70b9\u6570\uff0c\u8f6c\u6362\u540e\u7684\u5f62\u5f0f\u5927\u81f4\u662f&#8217;-ddd.ddd&#8230;&#8217;\u8fd9\u6837\u7684\u3002 \u5982\u679c\u8981\u8f6c\u6362\u7684\u662f\u8d1f\u503c\uff0c\u5219\u524d\u9762\u6709\u4e00\u4e2a\u8d1f\u53f7\u3002\u8f6c\u6362\u540e\u7684\u6570\u5b57\uff0c\u5728\u5c0f\u6570\u70b9\u540e\u9762\u7684\u6570\u5b57\u7684\u4e2a\u6570 \u7531[&#8220;.&#8221; prec]\u51b3\u5b9a\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a[&#8220;.&#8221; prec]\uff0c\u9ed8\u8ba4\u4e3a2\u4f4d\u7cbe\u5ea6\u3002<\/p>\n<p>(5) g \u4e00\u822c\u7684<br \/>\nArgs\u5fc5\u987b\u4e3a\u6d6e\u70b9\u6570\u3002\u88ab\u8f6c\u6362\u540e\u7684\u6570\u5b57\u603b\u662f\u5c3d\u53ef\u80fd\u7684\u7b80\u77ed(\u6709\u53ef\u80fd\u662ff\u6216e\u5f62\u5f0f\u7684)\u3002\u6709\u91cd\u8981\u610f\u4e49\u7684\u6570\u5b57\u7684\u957f\u5ea6\u7531[&#8220;.&#8221; prec]\u6765\u51b3\u5b9a\uff0c\u9ed8\u8ba4\u4e3a15\u4f4d(\u5305\u62ec\u6574\u6570\u4f4d\u548c\u5c0f\u6570\u4f4d)\u3002\u6570\u5b57\u524d\u540e\u76840\u90fd\u5c06\u88ab\u53bb\u6389\uff0c \u5c0f\u6570\u70b9\u4e5f\u53ea\u6709\u5728\u5fc5\u8981\u7684\u65f6\u5019\u624d\u663e\u793a\u51fa\u6765\u3002\u5982\u679c\u5c0f\u6570\u70b9\u5de6\u8fb9\u7684\u6570\u5b57\u5c0f\u4e8e\u7b49\u4e8e\u6307\u5b9a\u7684\u7cbe\u5ea6\uff0c\u5e76\u4e14\u6574\u4e2a\u503c\u5927\u4e8e\u6216\u7b49\u4e8e0.00001\u7684\u65f6\u5019\uff0c\u624d\u4f7f\u7528f\u7684\u663e\u793a\u683c\u5f0f\uff0c\u5426\u5219\u4f7f\u7528e(\u79d1\u5b66\u6280\u672f\u6cd5)<\/p>\n<p>(6) n Args\u5fc5\u987b\u662f\u6d6e\u70b9\u6570\u3002\u5f62\u5f0f\u548cf\u662f\u4e00\u6837\u7684\uff0c\u4e0d\u540c\u7684\u662f\u4f1a\u663e\u793a\u5343\u4f4d\u7b26\uff0c\u5982\uff1a1,123,444<\/p>\n<p>(7) m \u8d27\u5e01\u7c7b\u578b<br \/>\nArgs\u5fc5\u987b\u662f\u6d6e\u70b9\u6570\u3002\u80fd\u591f\u663e\u793a\u8d27\u5e01\u7b26\u53f7\uff0c\u53ef\u4ee5\u901a\u8fc7\u201c\u63a7\u5236\u9762\u677f\u201d\u6765\u8bbe\u7f6e\u3002\u5c0f\u6570\u70b9\u540e \u7684\u4f4d\u6570\u7531[&#8220;.&#8221; prec]\u51b3\u5b9a\uff0c\u5982\u679c\u6ca1\u7528[&#8220;.&#8221; prec]\uff0c\u5219\u9ed8\u8ba42\u4f4d\u3002<\/p>\n<p>(8) p \u6307\u9488<br \/>\nArgs\u5fc5\u987b\u662f\u4e00\u4e2a\u6307\u9488\u503c\u3002\u5c06\u6307\u9488\u8f6c\u6362\u4e3a8\u4e2a\u5b57\u7b26\u7684\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u3002<\/p>\n<p>(9) s \u5b57\u7b26\u4e32<br \/>\nArgs\u5fc5\u987b\u662f\u5b57\u7b26\uff0c\u5b57\u7b26\u4e32\u6216PChar\u503c\u3002 \u5982\u679c\u6307\u5b9a\u4e86[&#8220;.&#8221; prec]\uff0c\u5e76\u4e14\u5b57\u7b26\u4e32\u7684\u5b9e\u9645\u957f\u5ea6\u5927\u4e8e[&#8220;.&#8221; prec]\uff0c\u5219\u4ece\u5de6\u5230\u53f3\u622a\u53d6\u7cbe\u5ea6\u6307\u5b9a\u6570\u91cf\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4f59\u7684\u5220\u9664\u3002<\/p>\n<p>(10) x \u5341\u516d\u8fdb\u5236<br \/>\nArgs\u5fc5\u987b\u662f\u4e00\u4e2a\u6574\u578b\u6570\u3002 \u5982\u679c\u4f7f\u7528\u4e86[&#8220;.&#8221; prec]\uff0c\u4e0d\u8db3\u90e8\u5206\u8981\u75280\u8865\u9f50\u3002<\/p>\n<p>\u6ce8\u610f\uff1a[index &#8220;:&#8221;] [width] [&#8220;.&#8221; prec]\u53ef\u4ee5\u4f7f\u7528\u8fd9\u6837\u7684\u683c\u5f0f\uff1a<br \/>\nFormat(&#8216;%*.*f&#8217;, [8, 2, 123.456])<br \/>\n\u7b49\u4ef7\u4e8e\uff1aFormat(&#8216;%8.2f&#8217;, [123.456]).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>function Format(const Format: string; const Args: array [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-132","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"predecessor-version":[{"id":5211,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions\/5211"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}