: This article mainly describes how to format the amount in JQuery. For more information about PHP tutorials, see.
/*** Round the value (retain 2 decimal places) and format it into the amount format ** @ param num value (Number or String) * @ return value format String, for example, '200' * @ type String */function formatCurrency (num) {num = num. toString (). replace (/\ $ | \,/g, ''); if (isNaN (num) num =" 0 "; sign = (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);}/*** round the value (retain 1 decimal place) and format it into the amount form ** @ param num value (Number or String) * @ return: a String in the amount format, for example, '000000' * @ type String */function formatCurrencyTenThou (num) {num = num. toString (). replace (/\ $ | \,/g, ''); if (isNaN (num) num =" 0 "; sign = (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 the amount to format jQuery. extend ({formatFloat: function (src, pos) {var num = parseFloat (src ). toFixed (pos); num = num. toString (). replace (/\ $ | \,/g, ''); if (isNaN (num) num =" 0 "; sign = (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 above introduces the formatting of the amount in JQuery, including the content, and hopes to help friends who are interested in PHP tutorials.