{"id":217312,"date":"2021-05-11T10:24:13","date_gmt":"2021-05-11T02:24:13","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=217312"},"modified":"2021-04-26T10:24:39","modified_gmt":"2021-04-26T02:24:39","slug":"introduction-to-java-2","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/introduction-to-java-2.html","title":{"rendered":"Java Math floor\uff0cceil\uff0crint\u53caround\u7528\u6cd5\u7b80\u4ecb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nfloor\u539f\u610f\uff1a\u5730\u677f\u3002Math.floor\u51fd\u6570\u662f\u6c42\u4e00\u4e2a\u6d6e\u70b9\u6570\u7684\u5730\u677f\uff0c\u5c31\u662f\u6c42\u4e00\u4e2a\u6700\u63a5\u8fd1\u5b83\u7684\u6574\u6570\uff0c\u5b83\u7684\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u8fd9\u4e2a\u6d6e\u70b9\u6570\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

floor<\/strong>\u8fd4\u56de\u4e0d\u5927\u4e8e\u7684\u6700\u5927\u6574\u6570\u3002<\/p>\n

round<\/strong>\u5219\u662f4\u820d5\u5165\u7684\u8ba1\u7b97\uff0c\u5165\u7684\u65f6\u5019\u662f\u5230\u5927\u4e8e\u5b83\u7684\u6574\u4f53\u3002<\/p>\n

round<\/strong>\u8868\u793a\u201c\u56db\u820d\u4e94\u5165\u201d<\/strong>\uff0c\u7b97\u6cd5\u4e3aMath.floor\uff08x + 0.5\uff09<\/strong>\uff0c\u5373\u5c06\u539f\u6765\u7684\u6570\u5b57\u52a0\u4e0a0.5\u540e\u518d\u5411\u4e0b\u53d6\u6574\uff0c\u6240\u4ee5Math.round\uff0811.5\uff09<\/strong>\u7684\u7ed3\u679c\u4e3a12\uff0cMath.round\uff08-11.5\uff09\u7684\u7ed3\u679c\u4e3a-11\u3002<\/p>\n

\u6211\u4eec\u5148\u901a\u8fc7\u4ee5\u4e0b\u5b9e\u4f8b\u6765\u770b\u770bJava Math floor\uff0cceil\uff0crint\u53caround\u5404\u79cd\u65b9\u6cd5\u7684\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n

Test.java<\/strong><\/p>\n

\u5bfc\u5165java \u3002\u5b9e\u7528\u7a0b\u5e8f\u3002\u626b\u63cf\u4eea; \r\n \r\n\u516c\u5171\u7c7b\u6d4b\u8bd5{\u516c\u5171\u9759\u6001\u65e0\u6548\u4e3b\uff08\u5b57\u7b26\u4e32[ ] ARGS \uff09{\u626b\u63cf\u4eeaSC =\u65b0\u626b\u63cf\u4eea\uff08\u7cfb\u7edf\u3002\u5728\uff09;  \r\n        \u7cfb\u7edf\u3002\u51fa\u6765\u3002println \uff08\u201c\u8f93\u5165\u4e00\u4e2a\u6d6e\u70b9\u6570\uff1a\u201d \uff09;\r\n        \u800c\uff08SC \u3002hasNext \uff08\uff09\uff09      \r\n           \r\n          { double num = sc \u3002nextDouble \uff08\uff09;  \r\n                  \r\n            \u7cfb\u7edf\u3002\u51fa\u6765\u3002\u7684println \uff08\u201c Math.floor\uff08 \u201d + NUM + \u201c \uff09= \u201d +\u6570\u5b66\u3002\u697c\u5c42\uff08NUM \uff09\uff09;  \r\n            \u7cfb\u7edf\u3002\u51fa\u6765\u3002println \uff08\u201c Math.ceil\uff08\u201d + num + \u201c \uff09= \u201d +  \r\n             \u6570\u5b66\u3002ceil \uff08num \uff09\uff09;  \r\n            \u7cfb\u7edf\u3002\u51fa\u6765\u3002\u7684println \uff08\u201c Math.rint\uff08 \u201d + NUM + \u201c \uff09= \u201d +\u6570\u5b66\u3002RINT \uff08NUM \uff09\uff09;  \r\n            \u7cfb\u7edf\u3002\u51fa\u6765\u3002\u7684println \uff08\u201c Math.round\uff08 \u201d + NUM + \u201c \uff09= \u201d +\u6570\u5b66\u3002\u8f6e\uff08num \uff09\uff09;  \r\n        } } }<\/pre>\n

\u6267\u884c\u4ee5\u4e0a\u7a0b\u5e8f\u6d4b\u8bd5\u8f93\u51fa\uff1a<\/p>\n

$ javac\u6d4b\u8bd5\u3002\u722a\u54c7\r\n$ java Test\u8f93\u5165\u4e00\u4e2a\u6d6e\u70b9\u6570\uff1a2.2\u6570\u5b66\u3002floor \uff082.2 \uff09= 2.0 Math \u3002ceil \uff082.2 \uff09= 3.0\u6570\u5b66\u3002RINT \uff082.2 \uff09= 2.0\u6570\u5b66\u3002\u8f6e\uff082.2 \uff09= 2 - 2.2\u6570\u5b66\u3002\u5730\u677f\uff08-2.2 \uff09= - 3.0\u6570\u5b66\u3002ceil \uff08-2.2 \uff09= - \r\n\r\n  2.0\u6570\u5b66\u3002RINT \uff08 - 2.2 \uff09= - 2.0\u6570\u5b66\u3002\u8f6e\uff08 - 2.2 \uff09= - 2 - 2.5\u6570\u5b66\u3002\u5730\u677f\uff08-2.5 \uff09= - 3.0\u6570\u5b66\u3002ceil \uff08-2.5 \uff09= - 2.0\u6570\u5b66\u3002rint \uff08-2.5 \uff09= - 2.0\u6570\u5b66\u3002\u56db\u820d\u4e94\u5165\uff08-2.5 \uff09= -\r\n  \r\n  2 2.5\u6570\u5b66\u3002\u6700\u4f4e\uff082.5 \uff09= 2.0\u6570\u5b66\u3002ceil \uff082.5 \uff09= 3.0\u6570\u5b66\u3002rint \uff082.5 \uff09= 2.0\u6570\u5b66\u3002\u56db\u820d\u4e94\u5165\uff082.5 \uff09= 3 2.7\u6570\u5b66\u3002floor \uff082.7 \uff09= 2.0 Math \u3002ceil \uff082.7 \uff09= 3.0\u6570\u5b66\u3002\u6797\u7279\uff082.7\r\n  \r\n\uff09= 3.0\u6570\u5b66\u3002\u8f6e\uff082.7 \uff09= 3 - 2.7\u6570\u5b66\u3002\u5730\u677f\uff08-2.7 \uff09= - 3.0\u6570\u5b66\u3002\u5c0f\u533a\uff08 - 2.7 \uff09= - 2.0\u6570\u5b66\u3002rint \uff08-2.7 \uff09= - 3.0\u6570\u5b66\u3002\u56db\u820d\u4e94\u5165\uff08-2.7 \uff09= - 3 <\/pre>\n

\u89e3\u6790\u8f93\u51fa
\n1\uff0cMath.floor\uff08\uff09\u5411\u4e0b\u53d6\u6574\uff0c\u5373\u5c0f\u4e8e\u8fd9\u4e2a\u6570\u7684\u6700\u5927\u7684\u90a3\u4e2a\u4e00\u4f53\u3002<\/p>\n

\u6570\u5b66\u3002\u5730\u677f\uff082.2 \uff09= 2.0 ; \u6570\u5b66\u3002\u5730\u677f\uff08-2.2 \uff09= - 3.0 ; \u6570\u5b66\u3002\u5730\u677f\uff082.5 \uff09= 2.0 ; \u6570\u5b66\u3002\u5730\u677f\uff08-2.5 \uff09= - 3.0 ; \u6570\u5b66\u3002\u6700\u4f4e\uff082.7 \uff09= 2.0 ; \u6570\u5b66\u3002\u5730\u677f\uff08-2.7 \uff09= - 3.0 \r\n    \r\n  ;<\/pre>\n

2\uff0cMath.ceil\uff08\uff09\u5411\u4e0a\u53d6\u6574\uff0c\u5373\u5927\u4e8e\u8fd9\u4e2a\u6570\u7684\u6700\u5c0f\u7684\u90a3\u4e2a\u6574\u6570\u3002<\/p>\n

   \u6570\u5b66\u3002\u7ec6\u80de\uff082.2 \uff09= 3.0 ; \u6570\u5b66\u3002ceil \uff08-2.2 \uff09= - 2.0 ; \u6570\u5b66\u3002\u7ec6\u80de\uff082.5 \uff09= 3.0 ; \u6570\u5b66\u3002ceil \uff08-2.5 \uff09= - 2.0 ; \u6570\u5b66\u3002\u7ec6\u80de\uff082.7 \uff09= 3.0 ; \u6570\u5b66\u3002ceil \uff08-2.7 \uff09= - 2.0    \r\n       \r\n  ;<\/pre>\n

3\uff0cMath.rint\uff08\uff09\u8fd4\u56de\u6700\u63a5\u8fd1\u8be5\u503c\u7684\u90a3\u4e2a\u6574\u6570\u3002<\/p>\n

\u6ce8\u610f\uff1a\u5982\u679c\u5b58\u5728\u4e24\u4e2a\u8fd9\u6837\u7684\u6574\u6570\uff0c\u5219\u8fd4\u56de\u5176\u4e2d\u7684\u5076\u6570\u3002<\/p>\n

4\uff0cMath.round\uff08\uff09 \u56db\u820d\u4e94\u5165\uff0c\u4f46\u5f53\u53c2\u6570\u4e3a\u8d1f\u6570\u65f6\u4e0d\u592a\u597d\u7406\u89e3\uff0c\u76f4\u63a5\u4e0a\u6e90\u7801\u5e94\u8be5\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u6ce8\u610f\u8fd4\u56de\u7684\u662f\u6574\u578b\u3002<\/p>\n

   \u6570\u5b66\u3002\u56de\u5408\uff08x \uff09=\u6570\u5b66\u3002\u5730\u677f\uff08x + 0.5 \uff09<\/pre>\n

\u628a\u4ee5\u4e0a\u4ee3\u7801\u5e26\u5165\u4ee5\u4e0b\u5b9e\u4f8b\u6d4b\u8bd5\uff1a<\/p>\n

   \u6570\u5b66\u3002round \uff082.2 \uff09= 2 ;\u6570\u5b66\u3002round \uff08-2.2 \uff09= - 2 \uff1b\u6570\u5b66\u3002\u8f6e\uff082.5 \uff09= 3 ;\u6570\u5b66\u3002round \uff08-2.5 \uff09= - 2 \uff1b\u6570\u5b66\u3002\u8f6e\uff082.7 \uff09= 3 ;\u6570\u5b66\u3002\u56db\u820d\u4e94\u5165\uff08-2.7 \uff09= - 3<\/pre>\n","protected":false},"excerpt":{"rendered":"

floor\u8fd4\u56de\u4e0d\u5927\u4e8e\u7684\u6700\u5927\u6574\u6570\u3002 round\u5219\u662f4\u820d5\u5165\u7684\u8ba1\u7b97\uff0c\u5165\u7684\u65f6\u5019\u662f\u5230\u5927\u4e8e\u5b83\u7684\u6574\u4f53\u3002 round\u8868\u793a\u201c\u56db […]<\/p>\n","protected":false},"author":1481,"featured_media":217314,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-217312","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/217312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=217312"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/217312\/revisions"}],"predecessor-version":[{"id":217322,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/217312\/revisions\/217322"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/217314"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=217312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=217312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=217312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}