[{"data":1,"prerenderedAt":98},["ShallowReactive",2],{"content:\u002Fposts\u002F2022\u002Fmathjs":3,"surround:\u002Fposts\u002F2022\u002Fmathjs":87},{"id":4,"title":5,"body":6,"canonical":65,"categories":66,"date":68,"description":69,"draft":70,"extension":71,"image":65,"meta":72,"navigation":73,"path":74,"permalink":65,"readingTime":75,"recommend":65,"references":65,"seo":80,"sitemap":81,"stem":82,"tags":83,"type":65,"updated":68,"__hash__":86},"content\u002Fposts\u002F2022\u002Fmathjs.md","math.js 的使用",{"type":7,"value":8,"toc":58},"minimark",[9,13,24,27,35,42,45],[10,11,12],"h2",{"id":12},"安装",[14,15,21],"pre",{"className":16,"code":18,"language":19,"meta":20},[17],"language-shell","npm i mathjs\n","shell","",[22,23,18],"code",{"__ignoreMap":20},[10,25,26],{"id":26},"使用",[14,28,33],{"className":29,"code":31,"language":32,"meta":20},[30],"language-js","import { all, create } from \"mathjs\";\n\nconst config = {\n    number: \"BigNumber\",\n    precision: 20,\n};\nconst math = create(all, config);\n\nfunction calc(expression) {\n    if (expression) {\n        return math.number(math.evaluate(expression));\n    }\n    else {\n        return 0;\n    }\n}\n\u002F\u002F 可以使用表达式进行计算\nconsole.log(calc(`0.1 + 0.2`)); \u002F\u002F 0.3\n","js",[22,34,31],{"__ignoreMap":20},[36,37,38],"blockquote",{},[39,40,41],"p",{},"这里推介使用表达式的方式进行计算，灵活且精确",[10,43,44],{"id":44},"其他计算库",[46,47,48],"ul",{},[49,50,51],"li",{},[52,53,57],"a",{"href":54,"rel":55},"https:\u002F\u002Fcurrency.js.org\u002F",[56],"nofollow","currency.js",{"title":20,"searchDepth":59,"depth":59,"links":60},4,[61,63,64],{"id":12,"depth":62,"text":12},2,{"id":26,"depth":62,"text":26},{"id":44,"depth":62,"text":44},null,[67],"代码","2022-12-04 15:54:08","常用的 js 计算 精度解决方案",false,"md",{},true,"\u002Fposts\u002F2022\u002Fmathjs",{"text":76,"minutes":77,"time":78,"words":79},"1 min read",0.435,26100,87,{"title":5,"description":69},{"loc":74},"posts\u002F2022\u002Fmathjs",[84,32,85],"node","工具","sRuc3rjDKlnHkeo4euBP0r0506ijMDrSy5Qn_BWSecA",[88,93],{"title":89,"path":90,"stem":91,"date":92,"type":65,"children":-1},"n切换node版本","\u002Fposts\u002F2022\u002Fn-changenode-version","posts\u002F2022\u002Fn-changenode-version","2022-12-04 15:53:21",{"title":94,"path":95,"stem":96,"date":97,"type":65,"children":-1},"vite开发时问题及解决方案","\u002Fposts\u002F2022\u002Fvite-development-problems-and-solutions","posts\u002F2022\u002Fvite-development-problems-and-solutions","2022-12-04 15:58:34",1789642596418]