{"id":65077,"date":"2025-05-03T09:57:43","date_gmt":"2025-05-03T01:57:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65077\/"},"modified":"2025-05-03T09:57:43","modified_gmt":"2025-05-03T01:57:43","slug":"fastjson-%e8%bd%ac%e6%8d%a2-bigdecimal-%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bc%9a%e5%87%ba%e7%8e%b0%e7%b2%be%e5%ba%a6%e4%b8%a2%e5%a4%b1%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65077\/","title":{"rendered":"fastjson \u8f6c\u6362 BigDecimal \u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173111419238152.jpg\" class=\"aligncenter\" title=\"fastjson \u8f6c\u6362 BigDecimal \u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\uff1f\u63d2\u56fe\" alt=\"fastjson \u8f6c\u6362 BigDecimal \u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>fastjson\u8f6c\u6362bigdecimal\u5b58\u5728\u7cbe\u5ea6\u4e22\u5931\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528fastjson\u8f6c\u6362bigdecimal\u7c7b\u578b\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\u7684\u95ee\u9898\uff0c\u4f8b\u598212.0700\u8f6c\u6362\u540e\u53d8\u4e3a12.7\u3002\u539f\u56e0\u5728\u4e8efastjson\u9ed8\u8ba4\u4f7f\u7528double\u7c7b\u578b\u6765\u8868\u793a\u6570\u5b57\uff0c\u800cdouble\u7684\u7cbe\u5ea6\u6709\u9650\uff0c\u65e0\u6cd5\u7cbe\u786e\u8868\u793a\u6240\u6709\u5c0f\u6570\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528fastjson\u63d0\u4f9b\u7684bigdecimal\u7c7b\u578b\u7684\u652f\u6301\u3002\u4ecefastjson 1.2.6\u7248\u672c\u5f00\u59cb\uff0c\u63d0\u4f9b\u4e86bigdecimaltype\u6765\u652f\u6301\u5bf9bigdecimal\u7c7b\u578b\u7684\u8f6c\u6362\u3002\u5177\u4f53\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>import com.alibaba.fastjson.JSON;\nimport com.alibaba.fastjson.serializer.SerializerFeature;\n\npublic class BigDecimalExample {\n\n    public static void main(String[] args) {\n        BigDecimal value = new BigDecimal(\"12.0700\");\n\n        \/\/ \u4f7f\u7528BigDecimalType\u8f6c\u6362\n        String jsonStr = JSON.toJSONString(value, SerializerFeature.WriteBigDecimalAsPlain);\n\n        \/\/ \u4eceJSON\u8f6c\u6362\u56deBigDecimal\n        BigDecimal result = JSON.parseObject(jsonStr, BigDecimal.class);\n\n        System.out.println(result); \/\/ \u8f93\u51fa\uff1a12.0700\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4f7f\u7528bigdecimaltype\u540e\uff0cfastjson\u5c06\u76f4\u63a5\u4f7f\u7528\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u5b58\u50a8bigdecimal\uff0c\u907f\u514d\u4e86\u7cbe\u5ea6\u4e22\u5931\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662ffastjson \u8f6c\u6362 BigDecimal \u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>fastjson\u8f6c\u6362bigdecimal\u5b58\u5728\u7cbe\u5ea6\u4e22\u5931\u7684\u95ee\u9898 \u5f53\u4f7f\u7528fastjson\u8f6c\u6362bigdecimal\u7c7b\u578b\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\u7684\u95ee\u9898\uff0c\u4f8b\u598212.0700\u8f6c\u6362\u540e\u53d8\u4e3a12.7\u3002\u539f\u56e0\u5728\u4e8efastjson\u9ed8\u8ba4\u4f7f\u7528double\u7c7b\u578b\u6765\u8868\u793a\u6570\u5b57\uff0c\u800cdouble\u7684\u7cbe\u5ea6\u6709\u9650\uff0c\u65e0\u6cd5\u7cbe\u786e\u8868\u793a\u6240\u6709\u5c0f\u6570\u3002 \u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528fastjson\u63d0\u4f9b\u7684bigdecimal\u7c7b\u578b\u7684\u652f\u6301\u3002\u4ecefastjson 1.2.6\u7248\u672c\u5f00\u59cb\uff0c\u63d0\u4f9b\u4e86bigdecimaltype\u6765\u652f\u6301\u5bf9bigdecimal\u7c7b\u578b\u7684\u8f6c\u6362\u3002\u5177\u4f53\u7528\u6cd5\u5982\u4e0b\uff1a import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; public class BigDecimalExample { public static void main(String[] args) { BigDecimal value = new BigDecimal(&#8220;12.0700&#8221;); \/\/ \u4f7f\u7528BigDecimalType\u8f6c\u6362 String jsonStr = JSON.toJSONString(value, SerializerFeature.WriteBigDecimalAsPlain); \/\/ \u4eceJSON\u8f6c\u6362\u56deBigDecimal BigDecimal result = JSON.parseObject(jsonStr, BigDecimal.class); System.out.println(result); \/\/ \u8f93\u51fa\uff1a12.0700 } } \u767b\u5f55\u540e\u590d\u5236 \u5728\u4f7f\u7528bigdecimaltype\u540e\uff0cfastjson\u5c06\u76f4\u63a5\u4f7f\u7528\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u5b58\u50a8bigdecimal\uff0c\u907f\u514d\u4e86\u7cbe\u5ea6\u4e22\u5931\u7684\u95ee\u9898\u3002 \u4ee5\u4e0a\u5c31\u662ffastjson \u8f6c\u6362 BigDecimal \u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-65077","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65077","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=65077"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65077\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}