Formatted string: Amount

Source: Internet
Author: User
The input number in the input box is converted to the amount format:
/** Caculate * input: 100000 * output: 100,000 */(function ($) {var $ input = $ ("# cacu-input "), $ BTN = $ ("# cacu-BTN"), $ result = $ ("# cacu-result"), result = 0, // only allow the number and the back filternum = function (e) {// disable if (E. keycode <48 | E. keycode> 57) & E. keycode! = 8) {e. preventdefault (); Return false ;}}, // format the amount formatcurrency = function (Num) {num = num. tostring (). replace (/\ $ | \,/g, ''); If (isnan (Num) {num =" 0 ";} var sign, cents; // Sign = (number (Num)> = 0 )? '': '-'); // Plus or minus num = math. ABS (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;}, getcurrency = function (Num) {return num. replace (/\ $ | \,/g, '') ;}; $ input. on ("keypress", function (e) {filternum (e );}). on ("keyup", function (e) {var val = $ (this ). val (); val = formatcurrency (VAL); $ (this ). val (VAL) ;}); $ BTN. on ("click", function (e) {e. preventdefault (); var money = $ input. val (); money = getcurrency (money); Result = parseint (money/500, 10); $ result. text (result) ;}) ;}( window. jquery );

 

Formatted string: Amount

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.