C # and JS implementations turn finance into a 3-bit comma

Source: Internet
Author: User

1, C # with String.Format

ToString ("#,###.00")

2, JS method transferred from http://www.cnblogs.com/cssfirefly/p/3582027.html

(1)

var   num_s = "1232134456.546";    Alert (parsefloat (num_s). toLocaleString ());
(2)
function Format_number (nstr) {        nstr + = ';          x = Nstr.split ('. ');          x1 = x[0];          x2 = x.length > 1? '. ' + x[1]: ';          var rgx =/(\d+) (\d{3})/;          while (Rgx.test (x1)) {              x1 = x1.replace (RGX, ' $ ' + ', ' + ' $ ');          }          return x1 + x2;      }    var a= "53669988.000";    Alert (Format_number (a));    Alert (Format_number ("Wahh"));    Alert (format_number (0));    Alert (Format_number (6698.0023));

C # and JS implementations turn finance into a 3-bit comma

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.