{"id":1037,"date":"2023-03-12T09:36:25","date_gmt":"2023-03-12T01:36:25","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1037"},"modified":"2023-04-29T13:13:35","modified_gmt":"2023-04-29T05:13:35","slug":"js-controls-regular-input-of-floating-point-numbers","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/js-controls-regular-input-of-floating-point-numbers\/","title":{"rendered":"JS\u63a7\u5236\u6d6e\u70b9\u6570\u8f93\u5165\u6b63\u5219"},"content":{"rendered":"<p>\u9700\u6c42\uff1a<\/p>\n<p>1\u3001\u8fc7\u6ee4\u4ee50\u5f00\u5934<br \/>\n2\u3001\u53bb\u9664\u6240\u6709\u975e\u6570\u5b57\u548c\u5c0f\u6570\u70b9\u7684\u5b57\u7b26<br \/>\n3\u3001\u53bb\u6389\u91cd\u590d\u7684\u5c0f\u6570\u70b9<\/p>\n<p><!-- more --><\/p>\n<h2>JS\u5b9e\u65f6\u63a7\u5236\u6d6e\u70b9\u6570\u8f93\u5165<\/h2>\n<pre><code class=\"language-javascript\">amountWatcher (val, oldVal) {\n  console.log(val)\n  this.order.amount = val.replace(\/^[0]+\/, &#039;&#039;)\n  this.order.amount = this.order.amount.replace(\/[^\\d.]|\\.(?=[^.]*\\.)\/g, &#039;&#039;)\n}<\/code><\/pre>\n<h2>Java\u6821\u9a8c\u5b57\u7b26\u4e32\u5b9e\u73b0<\/h2>\n<pre><code class=\"language-java\">String[] source = { &quot;1,736, 233.00&quot;, &quot; 236. 233.73&quot;, &quot;36,233.235&quot;, &quot;34.00&quot; };\nString[] result = new String[source.length];\nfor (int i = 0; i &lt; source.length; i++) {\n    result[i] = source[i].replaceAll(&quot;([^\\\\d\\\\.]|\\\\.(?=[^\\\\.]*\\\\.))&quot;, &quot;&quot;);\n}\nSystem.out.println(Arrays.toString(result));\n\/\/ [1736233.00, 236233.73, 36233.235, 34.00]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\uff1a 1\u3001\u8fc7\u6ee4\u4ee50\u5f00\u5934 2\u3001\u53bb\u9664\u6240\u6709\u975e\u6570\u5b57\u548c\u5c0f\u6570\u70b9\u7684\u5b57\u7b26 3\u3001\u53bb\u6389\u91cd\u590d\u7684\u5c0f\u6570\u70b9 JS\u5b9e\u65f6\u63a7\u5236\u6d6e\u70b9\u6570\u8f93\u5165 am [&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-1037","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\/1037","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=1037"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1037\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}