Examples are as follows:
/** * Round the value and format it. * * @param num numeric value (Number or String) * @param cent decimal places to be retained * @param isThousand Whether a thousandth of 0 is required: not required, 1: required (numeric type); * @return A string in format, such as '1,234,567.45' * @type String */ function formatNumber(num,cent,isThousand) { num = num.toString().replace(//$|/,/g,''); // Check that the incoming value is the numeric type if(isNaN(num)) num = "0"; // Get the symbol (positive/negative number) sign = (num == (num = Math.abs(num)); num = Math.floor(num*Math.pow(10,cent)+0.50000000001); // Convert the specified decimal to an integer first. The extra decimal places are rounded by cents = num%Math.pow(10,cent); // Find the decimal values num = Math.floor(num/Math.pow(10,cent)).toString(); // Find the integer values cents = cents.toString(); // Convert the decimal places to a string to find the length of the decimal places// Make up the decimal places to the specified number while(cents.length<cent) cents = "0" + cents; if(isThousand) { // Format the integer part in a thousandth-quarter. 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)); } if (cent > 0) return (((sign)?'':'-') + num + '.' + cents); else return (((sign)?'':'-') + num); }The above article "JS" implements the thousandths of numerical values and the method of saving decimals (recommended) is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.