{"id":1743,"date":"2023-10-23T00:51:40","date_gmt":"2023-10-22T16:51:40","guid":{"rendered":"https:\/\/diuut.com\/?p=1743"},"modified":"2023-10-24T15:47:30","modified_gmt":"2023-10-24T07:47:30","slug":"java%e4%b8%adbigdecimal%e7%ae%80%e5%8d%95%e5%8f%8a%e5%a4%8d%e6%9d%82%e5%85%ac%e5%bc%8f%e8%ae%a1%e7%ae%97%e5%bc%80%e6%a0%b9%e3%80%81%e5%b0%8f%e6%95%b0%e6%ac%a1%e5%b9%82%e3%80%81%e4%b8%89%e8%a7%92","status":"publish","type":"post","link":"https:\/\/diuut.com\/?p=1743","title":{"rendered":"Java\u4e2dBigDecimal\u7b80\u5355\u53ca\u590d\u6742\u8ba1\u7b97(\u5f00\u6839\u3001\u5c0f\u6570\u6b21\u5e42\u3001\u4e09\u89d2\u51fd\u6570\u3001\u03c0\u503c\u7b49)"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>\u9700\u6c42<\/p><cite>\u91d1\u878d\u6216\u79d1\u5b66\u573a\u666f\u4e0b\uff0c\u8ba1\u7b97\u7cbe\u5ea6\u8981\u6c42\u8f83\u9ad8\uff0c\u8bbe\u8ba1\u7cbe\u5ea6\u8981\u6c42\u9ad8\u7684\u60c5\u51b5\u4e00\u822c\u5c31\u4f1a\u4f7f\u7528BigDecimal\u7c7b\u578b\uff0c\u6b64\u5904\u5c06\u5e38\u7528\u7684\u4ee5\u53ca\u53ef\u80fd\u4f1a\u7528\u5230\u7684\u8ba1\u7b97\u7c7b\u578b\u5217\u4e3e\u4e0b\u3002<\/cite><\/blockquote>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_66_1 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/diuut.com\/?p=1743\/#%E7%AE%80%E5%8D%95%E8%BF%90%E7%AE%97\" title=\"\u7b80\u5355\u8fd0\u7b97\">\u7b80\u5355\u8fd0\u7b97<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%8A%A0%E6%B3%95\" title=\"\u52a0\u6cd5\">\u52a0\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%87%8F%E6%B3%95\" title=\"\u51cf\u6cd5\">\u51cf\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/diuut.com\/?p=1743\/#%E4%B9%98%E6%B3%95\" title=\"\u4e58\u6cd5\">\u4e58\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/diuut.com\/?p=1743\/#%E9%99%A4%E6%B3%95\" title=\"\u9664\u6cd5\">\u9664\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%8F%96%E4%BD%99\" title=\"\u53d6\u4f59\">\u53d6\u4f59<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%B9%82%E8%BF%90%E7%AE%97\" title=\"\u5e42\u8fd0\u7b97\">\u5e42\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/diuut.com\/?p=1743\/#%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97\" title=\"\u6bd4\u8f83\u8fd0\u7b97\">\u6bd4\u8f83\u8fd0\u7b97<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%A4%8D%E6%9D%82%E8%BF%90%E7%AE%97\" title=\"\u590d\u6742\u8fd0\u7b97\">\u590d\u6742\u8fd0\u7b97<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%BC%80%E6%A0%B9%E8%BF%90%E7%AE%97\" title=\"\u5f00\u6839\u8fd0\u7b97\">\u5f00\u6839\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%B9%82%E8%BF%90%E7%AE%97-2\" title=\"\u5e42\u8fd0\u7b97\">\u5e42\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%AF%B9%E6%95%B0%E8%BF%90%E7%AE%97\" title=\"\u5bf9\u6570\u8fd0\u7b97\">\u5bf9\u6570\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/diuut.com\/?p=1743\/#%E4%BB%A5%E8%87%AA%E7%84%B6%E5%B8%B8%E6%95%B0e%E4%B8%BA%E5%BA%95%E7%9A%84%E6%8C%87%E6%95%B0%E5%87%BD%E6%95%B0%E8%BF%90%E7%AE%97\" title=\"\u4ee5\u81ea\u7136\u5e38\u6570e\u4e3a\u5e95\u7684\u6307\u6570\u51fd\u6570\u8fd0\u7b97\">\u4ee5\u81ea\u7136\u5e38\u6570e\u4e3a\u5e95\u7684\u6307\u6570\u51fd\u6570\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/diuut.com\/?p=1743\/#%E4%B8%89%E8%A7%92%E5%87%BD%E6%95%B0%E8%BF%90%E7%AE%97\" title=\"\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97\">\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%8F%8D%E4%B8%89%E8%A7%92%E5%87%BD%E6%95%B0%E8%BF%90%E7%AE%97\" title=\"\u53cd\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97\">\u53cd\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%8F%8D%E5%8F%8C%E6%9B%B2%E5%87%BD%E6%95%B0%E8%BF%90%E7%AE%97\" title=\"\u53cd\u53cc\u66f2\u51fd\u6570\u8fd0\u7b97\">\u53cd\u53cc\u66f2\u51fd\u6570\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/diuut.com\/?p=1743\/#%E9%98%B6%E4%B9%98%E8%BF%90%E7%AE%97\" title=\"\u9636\u4e58\u8fd0\u7b97\">\u9636\u4e58\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/diuut.com\/?p=1743\/#%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E7%B2%BE%E5%BA%A6%CF%80\" title=\"\u83b7\u53d6\u6307\u5b9a\u7cbe\u5ea6\u03c0\">\u83b7\u53d6\u6307\u5b9a\u7cbe\u5ea6\u03c0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/diuut.com\/?p=1743\/#%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E7%B2%BE%E5%BA%A6e\" title=\"\u83b7\u53d6\u6307\u5b9a\u7cbe\u5ea6e\">\u83b7\u53d6\u6307\u5b9a\u7cbe\u5ea6e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/diuut.com\/?p=1743\/#%E6%8C%87%E6%95%B0%E8%BF%90%E7%AE%97\" title=\"\u6307\u6570\u8fd0\u7b97\">\u6307\u6570\u8fd0\u7b97<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/diuut.com\/?p=1743\/#%E5%8F%96%E5%B0%8F%E6%95%B0%E5%87%BD%E6%95%B0\" title=\"\u53d6\u5c0f\u6570\u51fd\u6570\">\u53d6\u5c0f\u6570\u51fd\u6570<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"%E7%AE%80%E5%8D%95%E8%BF%90%E7%AE%97\"><\/span><strong>\u7b80\u5355\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>PS:\u5bf9\u8c61\u521d\u59cb\u5316\u65f6\u4f7f\u7528double\u7c7b\u578b\u6570\u636e\u8fdb\u884c\u6784\u9020\u4f1a\u5bfc\u81f4\u6570\u636e\u5931\u771f\uff0c\u56e0\u6b64\u4e0d\u5efa\u8bae\u4f7f\u7528\uff0c\u5982\u9700\u8981\u4f7f\u7528\u5c0f\u6570\u7c7b\u578b\uff0c\u63a8\u8350\u4f7f\u7528String\u8fdb\u884c\u6784\u9020\u3002<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%8A%A0%E6%B3%95\"><\/span><strong>\u52a0\u6cd5<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528 add \u65b9\u6cd5\u8fdb\u884c\u4e24\u4e2a BigDecimal \u5bf9\u8c61\u7684\u76f8\u52a0<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal result = BigDecimal.ZERO.add(BigDecimal.ONE);\n\/\/result=10;\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%87%8F%E6%B3%95\"><\/span><strong>\u51cf\u6cd5<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528&nbsp;<code>subtract<\/code>&nbsp;\u65b9\u6cd5\u8fdb\u884c\u4e24\u4e2a BigDecimal \u5bf9\u8c61\u7684\u76f8\u51cf<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal result = BigDecimal.TEN.subtract(BigDecimal.ONE);\n\/\/result=9;\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E4%B9%98%E6%B3%95\"><\/span><strong>\u4e58\u6cd5<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528&nbsp;<code>multiply<\/code>&nbsp;\u65b9\u6cd5\u8fdb\u884c\u4e24\u4e2a BigDecimal \u5bf9\u8c61\u7684\u76f8\u4e58<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal result = new BigDecimal(&quot;10&quot;).multiply( new BigDecimal(&quot;3&quot;));\n\/\/result=30;\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E9%99%A4%E6%B3%95\"><\/span><strong>\u9664\u6cd5<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528&nbsp;<code>divide<\/code>&nbsp;\u65b9\u6cd5\u8fdb\u884c\u4e24\u4e2a BigDecimal \u5bf9\u8c61\u7684\u76f8\u9664\uff0c\u53c2\u6570\u4e2d\u53ef\u4ee5\u6307\u5b9a\u591a\u79cd\u53d6\u4f59\u65b9\u5f0f<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal result = BigDecimal.TEN.divide(BigDecimal.valueOf(3), 2, RoundingMode.HALF_UP);\n\/\/result=3.33;\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%8F%96%E4%BD%99\"><\/span><strong>\u53d6\u4f59<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528&nbsp;<code>remainder<\/code>&nbsp;\u65b9\u6cd5\u83b7\u53d6\u4e24\u4e2a BigDecimal \u5bf9\u8c61\u7684\u4f59\u6570<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal result = BigDecimal.TEN.remainder(BigDecimal.valueOf(4));\n\/\/result=2;\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%B9%82%E8%BF%90%E7%AE%97\"><\/span><strong>\u5e42\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528&nbsp;<code>pow<\/code>&nbsp;\u65b9\u6cd5\u8ba1\u7b97 BigDecimal \u5bf9\u8c61\u7684\u5e42<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal result = BigDecimal.valueOf(3).pow(3);\n\/\/result=27;\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97\"><\/span><strong>\u6bd4\u8f83\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528 compare \u65b9\u6cd5\u83b7\u5f97\u6bd4\u8f83\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;1&quot;);\nBigDecimal num2 = new BigDecimal(&quot;2&quot;);\nBigDecimal num3 = new BigDecimal(&quot;2&quot;);\nint result1 = num1.compareTo(num2);\nSystem.out.println(&quot;result1=&quot; + result1);\nint result2 = num2.compareTo(num1);\nSystem.out.println(&quot;result2=&quot; + result2);\nint result3 = num2.compareTo(num3);\nSystem.out.println(&quot;result3=&quot; + result3);\n\n\/\/result1=-1\n\/\/result2=1\n\/\/result3=0\n<\/pre><\/div>\n\n\n<h3><span class=\"ez-toc-section\" id=\"%E5%A4%8D%E6%9D%82%E8%BF%90%E7%AE%97\"><\/span><strong>\u590d\u6742\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u4ee5\u4e0a\u662f\u5e38\u7528\u7684\u8fd0\u7b97\uff0c\u4f46\u662f\u5982\u679c\u8bbe\u8ba1\u590d\u6742\u5ea6\u5f00\u6839\u6216\u8005\u5c0f\u6570\u6b21\u5e42\u7684\u8bdd\uff0c\u81ea\u5e26\u7684\u65b9\u6cd5\u5c31\u4e0d\u6ee1\u8db3\u4e86\uff0c\u56e0\u6b64\uff0c\u9700\u8981\u5f15\u5165\u5176\u4ed6\u7684BigDecimal\u8fd0\u7b97\u7c7b\uff08<a href=\"https:\/\/github.com\/eobermuhlner\/big-math#bigdecimalmath\" data-type=\"URL\" data-id=\"https:\/\/github.com\/eobermuhlner\/big-math#bigdecimalmath\" target=\"_blank\" rel=\"noreferrer noopener\">big-math<\/a>\uff09,\u5f15\u5165\u4ee5\u4e0b\u4f9d\u8d56\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;!-- https:\/\/mvnrepository.com\/artifact\/ch.obermuhlner\/big-math --&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;ch.obermuhlner&lt;\/groupId&gt;\n    &lt;artifactId&gt;big-math&lt;\/artifactId&gt;\n    &lt;version&gt;2.3.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/pre><\/div>\n\n\n<p>\u53c2\u6570\u4e2d\u9700\u8981\u6307\u5b9a\u7cbe\u5ea6\u7684\u8bdd\u4f7f\u7528MathContext\u6765\u6307\u5b9a\u3002<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%BC%80%E6%A0%B9%E8%BF%90%E7%AE%97\"><\/span><strong>\u5f00\u6839\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528 sqrt \u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u5f00\u6839\u8fc7\u540e\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;2&quot;);\nBigDecimal result = BigDecimalMath.sqrt(num1, new MathContext(6));\nSystem.out.println(&quot;result=&quot;+result);\n\/\/ result=1.41421\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%B9%82%E8%BF%90%E7%AE%97-2\"><\/span><strong>\u5e42\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528&nbsp;<code>pow<\/code>&nbsp;\u65b9\u6cd5\u8ba1\u7b97 BigDecimal \u5bf9\u8c61\u7684\u5e42\uff08\u8ba1\u7b97x\u7684y\u6b21\u5e42\uff0c\u652f\u6301\u5c0f\u6570\uff09<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;2&quot;);\nBigDecimal num2 = new BigDecimal(&quot;1.5&quot;);\nBigDecimal result1 = BigDecimalMath.pow(num1, num2, new MathContext(6));\nSystem.out.println(&quot;result1=&quot; + result1);\nBigDecimal num3 = new BigDecimal(&quot;-1.5&quot;);\nBigDecimal result2 = BigDecimalMath.pow(num1, num3, new MathContext(6));\nSystem.out.println(&quot;result2=&quot; + result2);\n\n\/\/result1=2.82843\n\/\/result2=0.353553\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%AF%B9%E6%95%B0%E8%BF%90%E7%AE%97\"><\/span><strong>\u5bf9\u6570\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528 log \u7684\u591a\u79cd\u65b9\u6cd5\u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u5bf9\u6570\u8fd0\u7b97\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;2&quot;);\nBigDecimal result1 = BigDecimalMath.log(num1, new MathContext(6));\nSystem.out.println(&quot;result1=&quot;+result1);\nBigDecimal result2 = BigDecimalMath.log2(num1, new MathContext(6));\nSystem.out.println(&quot;result2=&quot;+result2);\nBigDecimal result3 = BigDecimalMath.log10(num1, new MathContext(6));\nSystem.out.println(&quot;result3=&quot;+result3);\n\n\/\/result1=0.693147\n\/\/result2=1\n\/\/result3=0.301030\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E4%BB%A5%E8%87%AA%E7%84%B6%E5%B8%B8%E6%95%B0e%E4%B8%BA%E5%BA%95%E7%9A%84%E6%8C%87%E6%95%B0%E5%87%BD%E6%95%B0%E8%BF%90%E7%AE%97\"><\/span><strong>\u4ee5\u81ea\u7136\u5e38\u6570e\u4e3a\u5e95\u7684\u6307\u6570\u51fd\u6570\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528 exp \u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u4ee5e\u4e3a\u5e95\u7684\u6307\u6570\u51fd\u6570\u8fd0\u7b97\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;2&quot;);\nBigDecimal result1 = BigDecimalMath.exp(num1, new MathContext(6));\nSystem.out.println(&quot;result1=&quot;+result1);\n\n\/\/result1=7.38906\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E4%B8%89%E8%A7%92%E5%87%BD%E6%95%B0%E8%BF%90%E7%AE%97\"><\/span><strong>\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;10&quot;);\nBigDecimal result1 = BigDecimalMath.sin(num1, new MathContext(6));\nSystem.out.println(&quot;result1=&quot;+result1);\nBigDecimal result2 = BigDecimalMath.cos(num1, new MathContext(6));\nSystem.out.println(&quot;result2=&quot;+result2);\nBigDecimal result3 = BigDecimalMath.tan(num1, new MathContext(6));\nSystem.out.println(&quot;result3=&quot;+result3);\nBigDecimal result4 = BigDecimalMath.cot(num1, new MathContext(6));\nSystem.out.println(&quot;result4=&quot;+result4);\n\n\/\/result1=-0.544021\n\/\/result2=-0.839072\n\/\/result3=0.648361\n\/\/result4=1.54235\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%8F%8D%E4%B8%89%E8%A7%92%E5%87%BD%E6%95%B0%E8%BF%90%E7%AE%97\"><\/span><strong>\u53cd\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u53cd\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;0.5&quot;);\nBigDecimal result1 = BigDecimalMath.asin(num1, new MathContext(6));\nSystem.out.println(&quot;result1=&quot;+result1);\nBigDecimal result2 = BigDecimalMath.acos(num1, new MathContext(6));\nSystem.out.println(&quot;result2=&quot;+result2);\nBigDecimal result3 = BigDecimalMath.atan(num1, new MathContext(6));\nSystem.out.println(&quot;result3=&quot;+result3);\nBigDecimal result4 = BigDecimalMath.acot(num1, new MathContext(6));\nSystem.out.println(&quot;result4=&quot;+result4);\n\n\/\/result1=0.523599\n\/\/result2=1.04720\n\/\/result3=0.463648\n\/\/result4=1.10715\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%8F%8D%E5%8F%8C%E6%9B%B2%E5%87%BD%E6%95%B0%E8%BF%90%E7%AE%97\"><\/span><strong><em>\u53cd\u53cc\u66f2\u51fd\u6570<\/em>\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u53cc\u53cd\u66f2\u51fd\u6570\u8fd0\u7b97\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;2&quot;);\nBigDecimal result1 = BigDecimalMath.asinh(num1, new MathContext(6));\nSystem.out.println(&quot;result1=&quot;+result1);\nBigDecimal result2 = BigDecimalMath.acosh(num1, new MathContext(6));\nSystem.out.println(&quot;result2=&quot;+result2);\nBigDecimal num2 = new BigDecimal(&quot;0.5&quot;);\nBigDecimal result3 = BigDecimalMath.atanh(num2, new MathContext(6));\nSystem.out.println(&quot;result3=&quot;+result3);\nBigDecimal num3 = new BigDecimal(&quot;-2&quot;);\nBigDecimal result4 = BigDecimalMath.acoth(num3, new MathContext(6));\nSystem.out.println(&quot;result4=&quot;+result4);\n\n\/\/result1=1.44364\n\/\/result2=1.31696\n\/\/result3=0.549306\n\/\/result4=-0.549306\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E9%98%B6%E4%B9%98%E8%BF%90%E7%AE%97\"><\/span><strong>\u9636\u4e58\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528 factorial \u65b9\u6cd5\u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u9636\u4e58\u8fd0\u7b97\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;5&quot;);\nBigDecimal result1 = BigDecimalMath.factorial(num1, new MathContext(6));\nSystem.out.println(&quot;result1=&quot; + result1);\n\n\/\/result1=120\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E7%B2%BE%E5%BA%A6%CF%80\"><\/span><strong>\u83b7\u53d6\u6307\u5b9a\u7cbe\u5ea6\u03c0<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal result1 = BigDecimalMath.pi(new MathContext(20));\nSystem.out.println(&quot;result1=&quot; + result1);\n\n\/\/result1=3.1415926535897932385\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E7%B2%BE%E5%BA%A6e\"><\/span><strong>\u83b7\u53d6\u6307\u5b9a\u7cbe\u5ea6e<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal result1 = BigDecimalMath.e(new MathContext(20));\nSystem.out.println(&quot;result1=&quot; + result1);\n\n\/\/result1=2.7182818284590452354\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E6%8C%87%E6%95%B0%E8%BF%90%E7%AE%97\"><\/span><strong>\u6307\u6570\u8fd0\u7b97<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528 exponent \u65b9\u6cd5\u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u6307\u6570\u8fd0\u7b97\u7ed3\u679c<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nint result1 = BigDecimalMath.exponent(BigDecimal.valueOf(1.456E99));\nSystem.out.println(&quot;result1=&quot; + result1);\n\n\/\/result1=99\n<\/pre><\/div>\n\n\n<h4><span class=\"ez-toc-section\" id=\"%E5%8F%96%E5%B0%8F%E6%95%B0%E5%87%BD%E6%95%B0\"><\/span><strong>\u53d6\u5c0f\u6570\u51fd\u6570<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4f7f\u7528 fractionalPart \u65b9\u6cd5\u83b7\u53d6BigDecimal \u5bf9\u8c61\u7684\u5c0f\u6570\u90e8\u5206<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nBigDecimal num1 = new BigDecimal(&quot;123.456&quot;);\nBigDecimal result1 = BigDecimalMath.fractionalPart(num1);\nSystem.out.println(&quot;result1=&quot; + result1);\n\n\/\/result1=0.456\n<\/pre><\/div>\n\n\n<p>\u4ee5\u4e0a\u662f\u8be5\u5de5\u5177\u7c7b\u4e2d\u6d89\u53ca\u7684\u5927\u90e8\u5206\u65b9\u6cd5\uff0c \u901a\u8fc7\u7ec4\u5408\u80fd\u591f\u8ba1\u7b97\u5927\u90e8\u5206\u590d\u6742\u573a\u666f\u7684\u516c\u5f0f\u3002<\/p>\n\n\n\n<p>\u8f6c\u8f7d\u8bf7\u7f72\u540d\uff08<a href=\"http:\/\/diuut.com\">Diuut<\/a>\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42 \u91d1\u878d\u6216\u79d1\u5b66\u573a\u666f\u4e0b\uff0c\u8ba1\u7b97\u7cbe\u5ea6\u8981\u6c42\u8f83\u9ad8\uff0c\u8bbe\u8ba1\u7cbe\u5ea6\u8981\u6c42\u9ad8\u7684\u60c5\u51b5\u4e00\u822c\u5c31\u4f1a\u4f7f\u7528BigDecimal\u7c7b\u578b\uff0c\u6b64\u5904\u5c06\u5e38\u7528<span class=\"more-button\"><a href=\"https:\/\/diuut.com\/?p=1743\" class=\"more-link\">view all . . .<span class=\"screen-reader-text\">Java\u4e2dBigDecimal\u7b80\u5355\u53ca\u590d\u6742\u8ba1\u7b97(\u5f00\u6839\u3001\u5c0f\u6570\u6b21\u5e42\u3001\u4e09\u89d2\u51fd\u6570\u3001\u03c0\u503c\u7b49)<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":657,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[65,37,53],"_links":{"self":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1743"}],"collection":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1743"}],"version-history":[{"count":20,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1743\/revisions"}],"predecessor-version":[{"id":1765,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1743\/revisions\/1765"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/media\/657"}],"wp:attachment":[{"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}