The formatting of the amount in jquery

Source: Internet
Author: User
/** * The value is rounded (Reserved 2 decimal places) after formatting into the amount of the form * * @param num Value (number or string) * @return amount format string, such as ' 1,234,567.45 ' * @type String *      /function FormatCurrency (num) {num = num.tostring (). Replace (/\$|\,/g, ");      if (IsNaN (num)) num = "0";      Sign = (num = = (num) = Math.Abs (num));      num = Math.floor (num*100+0.50000000001);      cents = num%100;      num = Math.floor (num/100). toString ();      if (cents<10) cents = "0" + cents; for (var i = 0; I < Math.floor ((num.length-(1+i))/3); i++) num = num.substring (0,num.length-(4*i+3)) + ', ' + num      . substring (num.length-(4*i+3));  Return ((sign)? ': '-') + num + '. ' + cents); /** * The value is rounded (reserved 1 decimal places) after formatting into the amount of the form * * @param num Value (number or string) * @return The amount format string, such as ' 1,234,567.4 ' * @type stri      NG */function Formatcurrencytenthou (num) {num = num.tostring (). Replace (/\$|\,/g, ");      if (IsNaN (num)) num = "0";      Sign = (num = = (num) = Math.Abs (num));      num = Math.floor (num*10+0.50000000001); CEnts = num%10;      num = Math.floor (NUM/10). toString (); for (var i = 0; I < Math.floor ((num.length-(1+i))/3); i++) num = num.substring (0,num.length-(4*i+3)) + ', ' + num      . substring (num.length-(4*i+3));  Return ((sign)? ': '-') + num + '. ' + cents);          }//Add amount formatted Jquery.extend ({formatfloat:function (src, pos) {var num = parsefloat (src). toFixed (POS);          num = num.tostring (). Replace (/\$|\,/g, ");          if (IsNaN (num)) num = "0";          Sign = (num = = (num) = Math.Abs (num));          num = Math.floor (num*100+0.50000000001);          cents = num%100;          num = Math.floor (num/100). toString ();          if (cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor (num.length-(1+i)/3); i++) num = num.substring (0,num.length-(4*i+3)) + ', ' +NUM.S          Ubstring (num.length-(4*i+3));      Return ((sign)? ': '-') + num + '. ' + cents);   }  });

The above describes the amount of jquery in the format, including aspects of the content, I hope the PHP tutorial interested in a friend to help.

  • 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.