{"id":474,"date":"2023-02-25T13:45:08","date_gmt":"2023-02-25T05:45:08","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=474"},"modified":"2023-04-29T20:54:43","modified_gmt":"2023-04-29T12:54:43","slug":"difference-between-rounding-to-fixed-and-round-in-js-data-processing","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/difference-between-rounding-to-fixed-and-round-in-js-data-processing\/","title":{"rendered":"JS\u5904\u7406\u6570\u636e\u56db\u820d\u4e94\u5165tofixed\u4e0eround\u7684\u533a\u522b"},"content":{"rendered":"<h2>tofixed\u65b9\u6cd5<\/h2>\n<p><code>toFixed()<\/code> \u65b9\u6cd5\u53ef\u628a Number \u56db\u820d\u4e94\u5165\u4e3a\u6307\u5b9a\u5c0f\u6570\u4f4d\u6570\u7684\u6570\u5b57\u3002\u4f8b\u5982\u5c06\u6570\u636eNum\u4fdd\u75592\u4f4d\u5c0f\u6570\uff0c\u5219\u8868\u793a\u4e3a\uff1a<code>toFixed(Num)<\/code>\u3002\u4f46\u662f\u5176\u56db\u820d\u4e94\u5165\u7684\u89c4\u5219\u4e0e\u6570\u5b66\u4e2d\u7684\u89c4\u5219\u4e0d\u540c\uff0c\u4f7f\u7528\u7684\u662f\u94f6\u884c\u5bb6\u820d\u5165\u89c4\u5219\uff0c<font color=\"#FF0000\"><strong>\u94f6\u884c\u5bb6\u820d\u5165:\u6240\u8c13\u94f6\u884c\u5bb6\u820d\u5165\u6cd5\uff0c\u5176\u5b9e\u8d28\u662f\u4e00\u79cd\u56db\u820d\u516d\u5165\u4e94\u53d6\u5076\uff08\u53c8\u79f0\u56db\u820d\u516d\u5165\u4e94\u7559\u53cc\uff09\u6cd5\u3002<\/strong><\/font>\u5177\u4f53\u89c4\u5219\u5982\u4e0b\uff1a<\/p>\n<p><!-- more --><\/p>\n<blockquote>\n<p>\u7b80\u5355\u6765\u8bf4\u5c31\u662f\uff1a\u56db\u820d\u516d\u5165\u4e94\u8003\u8651\uff0c\u4e94\u540e\u975e\u96f6\u5c31\u8fdb\u4e00\uff0c\u4e94\u540e\u4e3a\u96f6\u770b\u5947\u5076\uff0c\u4e94\u524d\u4e3a\u5076\u5e94\u820d\u53bb\uff0c\u4e94\u524d\u4e3a\u5947\u8981\u8fdb\u4e00\u3002<\/p>\n<\/blockquote>\n<p>\u663e\u7136\u8fd9\u79cd\u89c4\u5219\u4e0d\u7b26\u5408\u6211\u4eec\u5e73\u5e38\u5728\u6570\u636e\u5904\u7406\u4e2d\u7684\u65b9\u5f0f\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528<code>Math.round<\/code>\u65b9\u6cd5\u5b9e\u73b0\u4fdd\u7559\u6307\u5b9a\u4f4d\u6570\u56db\u820d\u4e94\u5165\u5904\u7406\u3002<\/p>\n<h2>round\u65b9\u6cd5<\/h2>\n<p><code>round()<\/code> \u65b9\u6cd5\u53ef\u628a\u4e00\u4e2a\u6570\u5b57\u820d\u5165\u4e3a\u6700\u63a5\u8fd1\u7684\u6574\u6570\u3002\u4f8b\u5982\uff1a<code>Math.round(x)<\/code>\uff0c\u5219\u662f\u5c06x\u53d6\u5176\u6700\u63a5\u8fd1\u7684\u6574\u6570\u3002\u5176\u53d6\u820d\u7684\u65b9\u6cd5\u4f7f\u7528\u7684\u662f\u56db\u820d\u4e94\u5165\u4e2d\u7684\u65b9\u6cd5\uff0c\u7b26\u5408\u6570\u5b66\u4e2d\u53d6\u820d\u7684\u89c4\u5219\u3002\u5bf9\u4e8e\u5c0f\u6570\u7684\u5904\u7406\u6ca1\u6709\u90a3\u4e48\u4fbf\u6377\uff0c\u4f46\u662f\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u8981\u6c42\uff0c\u8fdb\u884c\u81ea\u5b9a\u4e49\u7684\u5904\u7406\u3002<\/p>\n<p>\u4f8b\u5982\uff1a\u5bf9\u6570\u636eX\u8fdb\u884c\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u7684\u5904\u7406\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528<code>Math.round(X * 100) \/ 100.0<\/code>\u8fdb\u884c\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>tofixed\u65b9\u6cd5 toFixed() \u65b9\u6cd5\u53ef\u628a Number \u56db\u820d\u4e94\u5165\u4e3a\u6307\u5b9a\u5c0f\u6570\u4f4d\u6570\u7684\u6570\u5b57\u3002\u4f8b\u5982\u5c06\u6570\u636eNum [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[84],"class_list":["post-474","post","type-post","status-publish","format-standard","hentry","category-frontend-basic","tag-javascript"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=474"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/474\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}