{"id":37112,"date":"2024-11-26T08:28:17","date_gmt":"2024-11-26T00:28:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37112\/"},"modified":"2024-11-26T08:28:17","modified_gmt":"2024-11-26T00:28:17","slug":"java%e6%95%b0%e7%bb%84%e5%b0%8f%e6%95%b0%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37112\/","title":{"rendered":"java\u6570\u7ec4\u5c0f\u6570\u600e\u4e48\u529e"},"content":{"rendered":"<blockquote><p>\n  java \u6570\u7ec4\u53ef\u4f7f\u7528\u6d6e\u70b9\u7c7b\u578b\uff08float\/double\uff09\u5b58\u50a8\u5c0f\u6570\u30021.\u4f7f\u7528 float[] \u6570\u7ec4\uff1afloat[] decimals = new float[3]\uff1bdecimals[0] = 3.14f\uff1b2.\u4f7f\u7528 double[] \u6570\u7ec4\uff1adouble[] decimals = new double[3]\uff1bdecimals[0] = 3.14159265\uff1b\u8bbf\u95ee\u5c0f\u6570\uff1afloat firstdecimal = decimals[0]\uff1b\u6ce8\u610f\uff1afloat \u4e3a\u5355\u7cbe\u5ea6\uff0cdouble \u4e3a\u53cc\u7cbe\u5ea6\uff0c\u7cbe\u5ea6\u81f3\u5173\u91cd\u8981\u65f6\u4f7f\u7528\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111301215659093.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u5c0f\u6570\u600e\u4e48\u529e\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u5c0f\u6570\u600e\u4e48\u529e\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u6570\u7ec4\u4e2d\u5b58\u50a8\u5c0f\u6570<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5fc5\u987b\u5177\u6709\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6570\u7ec4\u53ea\u80fd\u5b58\u50a8\u6574\u578b\u5143\u7d20\u3002\u4f46\u662f\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u6d6e\u70b9\u7c7b\u578b\uff08\u5982 float \u6216 double\uff09\u6765\u5b58\u50a8\u5c0f\u6570\u3002<\/p>\n<p><strong>\u4f7f\u7528 Float \u6570\u7ec4<\/strong><\/p>\n<p>\u5982\u679c\u8981\u5b58\u50a8\u5c0f\u6570\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 float[] \u6570\u7ec4\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u521b\u5efa\u4e00\u4e2a float[] \u6570\u7ec4\u5e76\u5b58\u50a8\u5c0f\u6570\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>float[] decimals = new float[3];\ndecimals[0] = 3.14f;\ndecimals[1] = 6.02e23f;\ndecimals[2] = -1.618f;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Double \u6570\u7ec4<\/strong><\/p>\n<p>\u8981\u5b58\u50a8\u66f4\u7cbe\u786e\u7684\u5c0f\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 double[] \u6570\u7ec4\u3002double \u7c7b\u578b\u6bd4 float \u7c7b\u578b\u5b58\u50a8\u66f4\u5927\u7684\u503c\uff0c\u5e76\u4e14\u5177\u6709\u66f4\u9ad8\u7684\u7cbe\u5ea6\u3002<\/p>\n<pre>double[] decimals = new double[3];\ndecimals[0] = 3.14159265;\ndecimals[1] = 6.0221415e23;\ndecimals[2] = -1.61803398875;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5c0f\u6570<\/strong><\/p>\n<p>\u8981\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5c0f\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u8bbf\u95ee decimals \u6570\u7ec4\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5c0f\u6570\uff1a<\/p>\n<pre>float firstDecimal = decimals[0];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>float \u7c7b\u578b\u662f\u5c0f\u6570\u7684\u5355\u7cbe\u5ea6\u8868\u793a\u5f62\u5f0f\uff0c\u800c double \u7c7b\u578b\u662f\u5927\u6570\u7684\u53cc\u7cbe\u5ea6\u8868\u793a\u5f62\u5f0f\u3002<\/li>\n<li>\u4f7f\u7528 float \u7c7b\u578b\u5b58\u50a8\u5c0f\u6570\u53ef\u80fd\u4f1a\u5bfc\u81f4\u820d\u5165\u8bef\u5dee\u3002<\/li>\n<li>\u5982\u679c\u7cbe\u5ea6\u81f3\u5173\u91cd\u8981\uff0c\u53ef\u4ee5\u4f7f\u7528 BigDecimal \u7c7b\u6765\u5b58\u50a8\u548c\u64cd\u4f5c\u5c0f\u6570\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u5c0f\u6570\u600e\u4e48\u529e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java \u6570\u7ec4\u53ef\u4f7f\u7528\u6d6e\u70b9\u7c7b\u578b\uff08float\/double\uff09\u5b58\u50a8\u5c0f\u6570\u30021.\u4f7f\u7528 float[] \u6570\u7ec4\uff1afloat[] decimals = new float[3]\uff1bdecimals[0] = 3.14f\uff1b2.\u4f7f\u7528 double[] \u6570\u7ec4\uff1adouble[] decimals = new double[3]\uff1bdecimals[0] = 3.14159265\uff1b\u8bbf\u95ee\u5c0f\u6570\uff1afloat firstdecimal = decimals[0]\uff1b\u6ce8\u610f\uff1afloat \u4e3a\u5355\u7cbe\u5ea6\uff0cdouble \u4e3a\u53cc\u7cbe\u5ea6\uff0c\u7cbe\u5ea6\u81f3\u5173\u91cd\u8981\u65f6\u4f7f\u7528 Java \u6570\u7ec4\u4e2d\u5b58\u50a8\u5c0f\u6570 \u5728 Java \u4e2d\uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5fc5\u987b\u5177\u6709\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6570\u7ec4\u53ea\u80fd\u5b58\u50a8\u6574\u578b\u5143\u7d20\u3002\u4f46\u662f\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u6d6e\u70b9\u7c7b\u578b\uff08\u5982 float \u6216 double\uff09\u6765\u5b58\u50a8\u5c0f\u6570\u3002 \u4f7f\u7528 Float \u6570\u7ec4 \u5982\u679c\u8981\u5b58\u50a8\u5c0f\u6570\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 float[] \u6570\u7ec4\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u521b\u5efa\u4e00\u4e2a float[] \u6570\u7ec4\u5e76\u5b58\u50a8\u5c0f\u6570\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b float[] decimals = new float[3]; decimals[0] = 3.14f; decimals[1] = 6.02e23f; decimals[2] = -1.618f; \u767b\u5f55\u540e\u590d\u5236 [&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-37112","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37112","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=37112"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37112\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}