In js, the text box in the format of the data, according to the number of decimal digits, formatted into the corresponding xxx,xxx,xxx. XX (2 decimal places) or xxx,xxx,xxx (0 decimal places)
Source: Internet
Author: User
<span id="Label3"></p><pre><pre><span style="color: #008000;">//</span> <span style="color: #008000;">in js, the text box in the format of the data, according to the number of decimal digits, formatted into the corresponding xxx,xxx,xxx. XX (2 decimal places) or xxx,xxx,xxx (0 decimal)</span> function formatnum (num, n) {<span style="color: #008000;">///</span> <span style="color: #008000;">parameter description: num to format number n to retain decimal</span> digits num =<span style="color: #000000;"> String (num.tofixed (n)); </span> <span style="color: #0000ff;">var</span> re =/(-?\d+) (\d{<span style="color: #800080;">3</span>})/<span style="color: #000000;">; </span> <span style="color: #0000ff;"></span> while <span style="color: #800000;">"</span> <span style="color: #800000;">$1,$2</span> <span style="color: #800000;">"</span> <span style="color: #000000;">) </span><span style="color: #0000ff;">return</span> <span style="color: #000000;"> num; }</span></pre></pre><span class="cnblogs_code_collapse"><span class="cnblogs_code_collapse">View Code</span></span><p><p></p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.