{"id":171527,"date":"2024-11-07T03:29:17","date_gmt":"2024-11-06T19:29:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/171527\/"},"modified":"2024-11-07T03:29:18","modified_gmt":"2024-11-06T19:29:18","slug":"%e6%b7%ba%e6%9e%90%e6%95%b8%e6%93%9a%e5%ba%abfloat%e9%a1%9e%e5%9e%8b%e7%9a%84%e8%bd%89%e6%8f%9b%e6%96%b9%e6%b3%95-%e6%95%b8%e6%93%9a%e5%ba%abfloat%e9%a1%9e%e5%9e%8b%e5%a6%82%e4%bd%95%e8%bd%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/171527\/","title":{"rendered":"\u6dfa\u6790\u6578\u64da\u5eabfloat\u985e\u578b\u7684\u8f49\u63db\u65b9\u6cd5 (\u6578\u64da\u5eabfloat\u985e\u578b\u5982\u4f55\u8f49\u5316)"},"content":{"rendered":"<h1 id=\"%e6%b7%ba%e6%9e%90%e6%95%b8%e6%93%9a%e5%ba%abfloat%e9%a1%9e%e5%9e%8b%e7%9a%84%e8%bd%89%e6%8f%9b%e6%96%b9%e6%b3%95-bgOSSfOPlj\">\u6dfa\u6790\u6578\u64da\u5eabfloat\u985e\u578b\u7684\u8f49\u63db\u65b9\u6cd5<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u8a2d\u8a08\u4e2d\uff0c\u6578\u64da\u985e\u578b\u7684\u9078\u64c7\u5c0d\u65bc\u6578\u64da\u7684\u5b58\u5132\u548c\u8655\u7406\u81f3\u95dc\u91cd\u8981\u3002float\u985e\u578b\u4f5c\u70ba\u4e00\u7a2e\u5e38\u7528\u7684\u6578\u64da\u985e\u578b\uff0c\u4e3b\u8981\u7528\u65bc\u5b58\u5132\u6d6e\u9ede\u6578\u503c\u3002\u672c\u6587\u5c07\u63a2\u8a0efloat\u985e\u578b\u7684\u8f49\u63db\u65b9\u6cd5\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728\u4e0d\u540c\u60c5\u5883\u4e0b\u9032\u884c\u6578\u64da\u8f49\u63db\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%affloat%e9%a1%9e%e5%9e%8b%ef%bc%9f-bgOSSfOPlj\">\u4ec0\u9ebc\u662ffloat\u985e\u578b\uff1f<\/h2>\n<p>float\u985e\u578b\u662f\u4e00\u7a2e\u7528\u65bc\u8868\u793a\u5e36\u5c0f\u6578\u7684\u6578\u5b57\u7684\u6578\u64da\u985e\u578b\u3002\u5b83\u901a\u5e38\u7528\u65bc\u9700\u8981\u8868\u793a\u5c0f\u6578\u7684\u60c5\u6cc1\uff0c\u4f8b\u5982\u79d1\u5b78\u8a08\u7b97\u3001\u8ca1\u52d9\u5831\u8868\u7b49\u3002float\u985e\u578b\u7684\u512a\u52e2\u5728\u65bc\u5176\u80fd\u5920\u8868\u793a\u975e\u5e38\u5927\u7684\u6216\u975e\u5e38\u5c0f\u7684\u6578\u5b57\uff0c\u4f46\u540c\u6642\u4e5f\u5b58\u5728\u7cbe\u5ea6\u640d\u5931\u7684\u98a8\u96aa\u3002<\/p>\n<h2 id=\"float%e9%a1%9e%e5%9e%8b%e7%9a%84%e8%bd%89%e6%8f%9b%e9%9c%80%e6%b1%82-bgOSSfOPlj\">float\u985e\u578b\u7684\u8f49\u63db\u9700\u6c42<\/h2>\n<p>\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0c\u958b\u767c\u8005\u7d93\u5e38\u9700\u8981\u5c07float\u985e\u578b\u7684\u6578\u64da\u8f49\u63db\u70ba\u5176\u4ed6\u6578\u64da\u985e\u578b\uff0c\u4f8b\u5982\u6574\u6578\uff08int\uff09\u3001\u5b57\u7b26\u4e32\uff08string\uff09\u6216\u5176\u4ed6\u6578\u5b57\u985e\u578b\u3002\u9019\u7a2e\u8f49\u63db\u53ef\u80fd\u662f\u7531\u65bc\u6578\u64da\u8655\u7406\u7684\u9700\u6c42\u3001\u6578\u64da\u5eab\u7684\u8a2d\u8a08\u8b8a\u66f4\uff0c\u6216\u662f\u70ba\u4e86\u63d0\u9ad8\u8a08\u7b97\u7684\u7cbe\u5ea6\u3002<\/p>\n<h2 id=\"float%e9%a1%9e%e5%9e%8b%e7%9a%84%e8%bd%89%e6%8f%9b%e6%96%b9%e6%b3%95-bgOSSfOPlj\">float\u985e\u578b\u7684\u8f49\u63db\u65b9\u6cd5<\/h2>\n<h3 id=\"1-float%e8%bd%89%e6%95%b4%e6%95%b8-bgOSSfOPlj\">1. float\u8f49\u6574\u6578<\/h3>\n<p>\u5c07float\u985e\u578b\u8f49\u63db\u70ba\u6574\u6578\u985e\u578b\u6642\uff0c\u901a\u5e38\u6703\u4f7f\u7528\u622a\u65b7\u6216\u56db\u6368\u4e94\u5165\u7684\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u5169\u7a2e\u5e38\u898b\u7684\u8f49\u63db\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li><code>CAST<\/code>\u51fd\u6578\uff1a\u4f7f\u7528SQL\u4e2d\u7684CAST\u51fd\u6578\u53ef\u4ee5\u5c07float\u8f49\u63db\u70ba\u6574\u6578\u3002<\/li>\n<pre><code>SELECT CAST(your_float_column AS INT) FROM your_table;<\/code><\/pre>\n<li><code>ROUND<\/code>\u51fd\u6578\uff1a\u5982\u679c\u9700\u8981\u56db\u6368\u4e94\u5165\uff0c\u53ef\u4ee5\u4f7f\u7528ROUND\u51fd\u6578\u3002<\/li>\n<pre><code>SELECT ROUND(your_float_column) FROM your_table;<\/code><\/pre>\n<\/ul>\n<h3 id=\"2-float%e8%bd%89%e5%ad%97%e7%ac%a6%e4%b8%b2-bgOSSfOPlj\">2. float\u8f49\u5b57\u7b26\u4e32<\/h3>\n<p>\u5c07float\u985e\u578b\u8f49\u63db\u70ba\u5b57\u7b26\u4e32\u985e\u578b\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528CAST\u6216CONVERT\u51fd\u6578\u3002\u9019\u5728\u9700\u8981\u5c07\u6578\u64da\u4ee5\u6587\u672c\u5f62\u5f0f\u986f\u793a\u6642\u975e\u5e38\u6709\u7528\u3002<\/p>\n<ul>\n<li><code>CAST<\/code>\u51fd\u6578\uff1a<\/li>\n<pre><code>SELECT CAST(your_float_column AS VARCHAR) FROM your_table;<\/code><\/pre>\n<li><code>CONVERT<\/code>\u51fd\u6578\uff1a<\/li>\n<pre><code>SELECT CONVERT(VARCHAR, your_float_column) FROM your_table;<\/code><\/pre>\n<\/ul>\n<h3 id=\"3-%e6%95%b4%e6%95%b8%e8%bd%89float-bgOSSfOPlj\">3. \u6574\u6578\u8f49float<\/h3>\n<p>\u5c07\u6574\u6578\u8f49\u63db\u70bafloat\u985e\u578b\u76f8\u5c0d\u7c21\u55ae\uff0c\u901a\u5e38\u53ef\u4ee5\u76f4\u63a5\u9032\u884c\u8f49\u63db\uff0c\u56e0\u70ba\u6574\u6578\u53ef\u4ee5\u7121\u640d\u5730\u8f49\u63db\u70ba\u6d6e\u9ede\u6578\u3002<\/p>\n<pre><code>SELECT CAST(your_int_column AS FLOAT) FROM your_table;<\/code><\/pre>\n<h3 id=\"4-%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%89float-bgOSSfOPlj\">4. \u5b57\u7b26\u4e32\u8f49float<\/h3>\n<p>\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70bafloat\u985e\u578b\u6642\uff0c\u9700\u8981\u78ba\u4fdd\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u6b63\u78ba\uff0c\u5426\u5247\u6703\u5c0e\u81f4\u8f49\u63db\u5931\u6557\u3002\u53ef\u4ee5\u4f7f\u7528CAST\u6216CONVERT\u51fd\u6578\u9032\u884c\u8f49\u63db\u3002<\/p>\n<pre><code>SELECT CAST(your_string_column AS FLOAT) FROM your_table;<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-bgOSSfOPlj\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u9032\u884cfloat\u985e\u578b\u7684\u8f49\u63db\u6642\uff0c\u958b\u767c\u8005\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u7cbe\u5ea6\u640d\u5931\uff1afloat\u985e\u578b\u5728\u8f49\u63db\u904e\u7a0b\u4e2d\u53ef\u80fd\u6703\u51fa\u73fe\u7cbe\u5ea6\u640d\u5931\uff0c\u7279\u5225\u662f\u5728\u5f9efloat\u8f49\u6574\u6578\u6642\u3002<\/li>\n<li>\u683c\u5f0f\u6aa2\u67e5\uff1a\u5728\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70bafloat\u6642\uff0c\u5fc5\u9808\u78ba\u4fdd\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u6b63\u78ba\uff0c\u5426\u5247\u6703\u5f15\u767c\u932f\u8aa4\u3002<\/li>\n<li>\u6027\u80fd\u8003\u91cf\uff1a\u983b\u7e41\u7684\u6578\u64da\u985e\u578b\u8f49\u63db\u53ef\u80fd\u6703\u5f71\u97ff\u6578\u64da\u5eab\u7684\u6027\u80fd\uff0c\u56e0\u6b64\u61c9\u8b39\u614e\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-bgOSSfOPlj\">\u7e3d\u7d50<\/h2>\n<p>float\u985e\u578b\u7684\u8f49\u63db\u65b9\u6cd5\u5728\u6578\u64da\u5eab\u64cd\u4f5c\u4e2d\u626e\u6f14\u8457\u91cd\u8981\u89d2\u8272\u3002\u4e86\u89e3\u5982\u4f55\u6709\u6548\u5730\u9032\u884c\u9019\u4e9b\u8f49\u63db\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u8655\u7406\u6578\u64da\uff0c\u63d0\u5347\u61c9\u7528\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u652f\u6301\u60a8\u7684\u696d\u52d9\u9700\u6c42\uff0c\u7121\u8ad6\u662f\u6578\u64da\u5b58\u5132\u9084\u662f\u8a08\u7b97\u8655\u7406\uff0cServer.HK\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6dfa\u6790\u6578\u64da\u5eab\u4e2dfloat\u985e\u578b\u7684\u8f49\u63db\u65b9\u6cd5\uff0c\u63a2\u8a0e\u5982\u4f55\u6709\u6548\u5730\u5c07float\u6578\u64da\u8f49\u5316\u70ba\u5176\u4ed6\u6578\u64da\u985e\u578b\u4ee5\u63d0\u9ad8\u6578\u64da\u8655\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-171527","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=171527"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171527\/revisions"}],"predecessor-version":[{"id":171528,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171527\/revisions\/171528"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=171527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=171527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=171527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}