{"id":1042413,"date":"2024-12-31T12:57:20","date_gmt":"2024-12-31T04:57:20","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1042413.html"},"modified":"2024-12-31T12:57:23","modified_gmt":"2024-12-31T04:57:23","slug":"python%e5%a6%82%e4%bd%95%e4%bb%8e%e6%b5%ae%e7%82%b9%e6%95%b0%e8%bd%ac%e5%ad%97%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1042413.html","title":{"rendered":"python\u5982\u4f55\u4ece\u6d6e\u70b9\u6570\u8f6c\u5b57\u7b26"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/2ed27357-038c-4228-8b87-5b12b014d7fa.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u4ece\u6d6e\u70b9\u6570\u8f6c\u5b57\u7b26\" \/><\/p>\n<p><p> <strong>Python\u4ece\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5176\u4e2d\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u7684 <code>str()<\/code> \u51fd\u6570\u3001\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c <code>repr()<\/code> \u51fd\u6570\u3002<\/strong> \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u8fd9\u4e9b\u65b9\u6cd5\u5e76\u63d0\u4f9b\u793a\u4f8b\u4ee3\u7801\u6765\u8bf4\u660e\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001str()\u51fd\u6570<\/p>\n<\/p>\n<p><p>Python\u4e2d\u7684 <code>str()<\/code> \u51fd\u6570\u662f\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u4e4b\u4e00\u3002\u5b83\u53ef\u4ee5\u5c06\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 <code>str()<\/code> \u51fd\u6570\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">float_num = 123.456<\/p>\n<p>str_num = str(float_num)<\/p>\n<p>print(str_num)  # \u8f93\u51fa: &#39;123.456&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u7b80\u5355\u3001\u76f4\u89c2\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\uff0c\u5982\u767e\u5206\u53f7\u683c\u5f0f\u5316\u3001<code>str.format()<\/code> \u65b9\u6cd5\u548cf\u5b57\u7b26\u4e32\uff08\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff09\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4e0d\u4ec5\u53ef\u4ee5\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u8fd8\u53ef\u4ee5\u6307\u5b9a\u8f93\u51fa\u683c\u5f0f\u3002<\/p>\n<\/p>\n<ol>\n<li>\u767e\u5206\u53f7\u683c\u5f0f\u5316<\/li>\n<\/ol>\n<p><p>\u767e\u5206\u53f7\u683c\u5f0f\u5316\u662fPython\u4e2d\u8f83\u65e9\u7684\u4e00\u79cd\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>%<\/code> \u64cd\u4f5c\u7b26\u6765\u6307\u5b9a\u6d6e\u70b9\u6570\u7684\u683c\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">float_num = 123.456<\/p>\n<p>str_num = &#39;%.2f&#39; % float_num<\/p>\n<p>print(str_num)  # \u8f93\u51fa: &#39;123.46&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code>%.2f<\/code> \u8868\u793a\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>str.format() \u65b9\u6cd5<\/li>\n<\/ol>\n<p><p><code>str.format()<\/code> \u65b9\u6cd5\u662fPython3\u4e2d\u5f15\u5165\u7684\u4e00\u79cd\u66f4\u5f3a\u5927\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\u3002\u5b83\u53ef\u4ee5\u66f4\u7075\u6d3b\u5730\u6307\u5b9a\u6d6e\u70b9\u6570\u7684\u683c\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">float_num = 123.456<\/p>\n<p>str_num = &#39;{:.2f}&#39;.format(float_num)<\/p>\n<p>print(str_num)  # \u8f93\u51fa: &#39;123.46&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code>{:.2f}<\/code> \u8868\u793a\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>f\u5b57\u7b26\u4e32\uff08\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff09<\/li>\n<\/ol>\n<p><p>f\u5b57\u7b26\u4e32\u662fPython3.6\u4e2d\u5f15\u5165\u7684\u4e00\u79cd\u65b0\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\u3002\u5b83\u4f7f\u7528\u66f4\u7b80\u5355\u7684\u8bed\u6cd5\u6765\u63d2\u5165\u53d8\u91cf\u548c\u8868\u8fbe\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">float_num = 123.456<\/p>\n<p>str_num = f&#39;{float_num:.2f}&#39;<\/p>\n<p>print(str_num)  # \u8f93\u51fa: &#39;123.46&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code>{float_num:.2f}<\/code> \u8868\u793a\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001repr()\u51fd\u6570<\/p>\n<\/p>\n<p><p><code>repr()<\/code> \u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u8868\u793a\u5f62\u5f0f\uff0c\u901a\u5e38\u7528\u4e8e\u8c03\u8bd5\u3002\u5b83\u53ef\u4ee5\u4fdd\u7559\u6d6e\u70b9\u6570\u7684\u7cbe\u5ea6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">float_num = 123.456<\/p>\n<p>str_num = repr(float_num)<\/p>\n<p>print(str_num)  # \u8f93\u51fa: &#39;123.456&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0e <code>str()<\/code> \u51fd\u6570\u4e0d\u540c\uff0c<code>repr()<\/code> \u51fd\u6570\u66f4\u5173\u6ce8\u5bf9\u8c61\u7684\u51c6\u786e\u8868\u793a\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u79d1\u5b66\u8ba1\u6570\u6cd5<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u79d1\u5b66\u8ba1\u6570\u6cd5\u8868\u793a\u7684\u5b57\u7b26\u4e32\u3002\u53ef\u4ee5\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6765\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">float_num = 123456.789<\/p>\n<p>str_num = &#39;{:.2e}&#39;.format(float_num)<\/p>\n<p>print(str_num)  # \u8f93\u51fa: &#39;1.23e+05&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code>{:.2e}<\/code> \u8868\u793a\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u7684\u79d1\u5b66\u8ba1\u6570\u6cd5\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u81ea\u5b9a\u4e49\u51fd\u6570<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u7279\u6b8a\u573a\u666f\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u81ea\u5b9a\u4e49\u51fd\u6570\u6765\u5b9e\u73b0\u6d6e\u70b9\u6570\u5230\u5b57\u7b26\u4e32\u7684\u8f6c\u6362\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def float_to_str(float_num, precision=2):<\/p>\n<p>    return f&#39;{float_num:.{precision}f}&#39;<\/p>\n<p>float_num = 123.456<\/p>\n<p>str_num = float_to_str(float_num, 3)<\/p>\n<p>print(str_num)  # \u8f93\u51fa: &#39;123.456&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a <code>float_to_str<\/code> \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u6d6e\u70b9\u6570\u548c\u4e00\u4e2a\u53ef\u9009\u7684\u7cbe\u5ea6\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u4fdd\u7559\u6307\u5b9a\u5c0f\u6570\u4f4d\u6570\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u5904\u7406\u7279\u6b8a\u503c<\/p>\n<\/p>\n<p><p>\u6d6e\u70b9\u6570\u4e2d\u53ef\u80fd\u5305\u542b\u4e00\u4e9b\u7279\u6b8a\u503c\uff0c\u5982\u65e0\u7a77\u5927\u548cNaN\uff08\u975e\u6570\u5b57\uff09\u3002\u5728\u5c06\u8fd9\u4e9b\u7279\u6b8a\u503c\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u65f6\uff0c\u9700\u8981\u7279\u522b\u6ce8\u610f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>float_num_pos_inf = float(&#39;inf&#39;)<\/p>\n<p>float_num_neg_inf = float(&#39;-inf&#39;)<\/p>\n<p>float_num_nan = float(&#39;nan&#39;)<\/p>\n<p>print(str(float_num_pos_inf))  # \u8f93\u51fa: &#39;inf&#39;<\/p>\n<p>print(str(float_num_neg_inf))  # \u8f93\u51fa: &#39;-inf&#39;<\/p>\n<p>print(str(float_num_nan))      # \u8f93\u51fa: &#39;nan&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>str()<\/code> \u51fd\u6570\u5c06\u65e0\u7a77\u5927\u548cNaN\u503c\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u5904\u7406\u5927\u6570\u503c\u548c\u7cbe\u5ea6\u95ee\u9898<\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u975e\u5e38\u5927\u7684\u6d6e\u70b9\u6570\u6216\u9700\u8981\u9ad8\u7cbe\u5ea6\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528Python\u7684 <code>decimal<\/code> \u6a21\u5757\u3002<code>decimal<\/code> \u6a21\u5757\u63d0\u4f9b\u4e86\u9ad8\u7cbe\u5ea6\u7684\u6d6e\u70b9\u6570\u8fd0\u7b97\uff0c\u5e76\u652f\u6301\u5c06 <code>Decimal<\/code> \u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from decimal import Decimal<\/p>\n<p>float_num = Decimal(&#39;123456789.123456789123456789&#39;)<\/p>\n<p>str_num = str(float_num)<\/p>\n<p>print(str_num)  # \u8f93\u51fa: &#39;123456789.123456789123456789&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>Decimal<\/code> \u5bf9\u8c61\u6765\u8868\u793a\u9ad8\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u5305\u62ec\u4f7f\u7528 <code>str()<\/code> \u51fd\u6570\u3001\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c <code>repr()<\/code> \u51fd\u6570\u7b49\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\u548c\u4f18\u52bf\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5b9e\u73b0\u6d6e\u70b9\u6570\u5230\u5b57\u7b26\u4e32\u7684\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528 <code>str()<\/code> \u51fd\u6570\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u573a\u666f\u3002\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u65b9\u6cd5\uff08\u5982\u767e\u5206\u53f7\u683c\u5f0f\u5316\u3001<code>str.format()<\/code> \u65b9\u6cd5\u548cf\u5b57\u7b26\u4e32\uff09\u63d0\u4f9b\u4e86\u66f4\u7075\u6d3b\u7684\u683c\u5f0f\u63a7\u5236\uff0c\u9002\u7528\u4e8e\u9700\u8981\u6307\u5b9a\u8f93\u51fa\u683c\u5f0f\u7684\u573a\u666f\u3002<code>repr()<\/code> \u51fd\u6570\u5219\u66f4\u5173\u6ce8\u5bf9\u8c61\u7684\u51c6\u786e\u8868\u793a\uff0c\u9002\u7528\u4e8e\u8c03\u8bd5\u573a\u666f\u3002\u79d1\u5b66\u8ba1\u6570\u6cd5\u548c\u81ea\u5b9a\u4e49\u51fd\u6570\u5219\u9002\u7528\u4e8e\u7279\u6b8a\u9700\u6c42\u7684\u573a\u666f\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u6ce8\u610f\u5904\u7406\u7279\u6b8a\u503c\u548c\u5927\u6570\u503c\u7684\u7cbe\u5ea6\u95ee\u9898\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u4e86\u89e3Python\u4ece\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\u6709\u6240\u5e2e\u52a9\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5b9e\u73b0\u6d6e\u70b9\u6570\u5230\u5b57\u7b26\u4e32\u7684\u8f6c\u6362\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>str()<\/code>\u51fd\u6570\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002\u53ea\u9700\u5c06\u6d6e\u70b9\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9<code>str()<\/code>\u51fd\u6570\u5373\u53ef\u3002\u4f8b\u5982\uff0c<code>str(3.14)<\/code>\u5c06\u8fd4\u56de\u5b57\u7b26\u4e32<code>&#39;3.14&#39;<\/code>\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\uff0c\u4f8b\u5982<code>f&quot;{float_number}&quot;<\/code>\uff0c\u5176\u4e2d<code>float_number<\/code>\u662f\u9700\u8981\u8f6c\u6362\u7684\u6d6e\u70b9\u6570\u3002<\/p>\n<p><strong>\u6709\u4ec0\u4e48\u65b9\u6cd5\u53ef\u4ee5\u683c\u5f0f\u5316\u6d6e\u70b9\u6570\u5728\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u65f6\u7684\u663e\u793a\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6765\u63a7\u5236\u6d6e\u70b9\u6570\u7684\u663e\u793a\u683c\u5f0f\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>format()<\/code>\u51fd\u6570\u6216\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff08f-strings\uff09\u53ef\u4ee5\u6307\u5b9a\u5c0f\u6570\u4f4d\u6570\u3002\u6bd4\u5982\uff0c<code>&quot;{:.2f}&quot;.format(3.14159)<\/code>\u6216<code>f&quot;{3.14159:.2f}&quot;<\/code>\u5c06\u8fd4\u56de<code>&#39;3.14&#39;<\/code>\uff0c\u4ec5\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002\u6b64\u5916\uff0c<code>round()<\/code>\u51fd\u6570\u4e5f\u53ef\u4ee5\u7528\u4e8e\u63a7\u5236\u6d6e\u70b9\u6570\u7684\u5c0f\u6570\u4f4d\u6570\u3002<\/p>\n<p><strong>\u5728\u8f6c\u6362\u6d6e\u70b9\u6570\u4e3a\u5b57\u7b26\u4e32\u65f6\uff0c\u5982\u4f55\u5904\u7406\u79d1\u5b66\u8ba1\u6570\u6cd5\uff1f<\/strong><br \/>Python\u9ed8\u8ba4\u4f1a\u4ee5\u79d1\u5b66\u8ba1\u6570\u6cd5\u8868\u793a\u975e\u5e38\u5927\u7684\u6216\u975e\u5e38\u5c0f\u7684\u6d6e\u70b9\u6570\u3002\u5728\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>&quot;{:.nf}&quot;.format(float_number)<\/code>\u7684\u65b9\u5f0f\u6765\u907f\u514d\u79d1\u5b66\u8ba1\u6570\u6cd5\uff0c\u5176\u4e2d<code>n<\/code>\u8868\u793a\u5e0c\u671b\u4fdd\u7559\u7684\u5c0f\u6570\u4f4d\u6570\u3002\u4f8b\u5982\uff0c<code>&quot;{:e}&quot;.format(0.000123)<\/code>\u5c06\u8fd4\u56de\u5b57\u7b26\u4e32<code>&#39;1.230000e-04&#39;<\/code>\uff0c\u800c<code>&quot;{:.6f}&quot;.format(0.000123)<\/code>\u5219\u4f1a\u5f97\u5230<code>&#39;0.000123&#39;<\/code>\uff0c\u4f7f\u5176\u4ee5\u5e38\u89c4\u5c0f\u6570\u5f62\u5f0f\u663e\u793a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4ece\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5176\u4e2d\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u7684 str() \u51fd\u6570\u3001\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c [&hellip;]","protected":false},"author":3,"featured_media":1042419,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1042413"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1042413"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1042413\/revisions"}],"predecessor-version":[{"id":1042421,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1042413\/revisions\/1042421"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1042419"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1042413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1042413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1042413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}