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