This example uses no negative signs, such as -52, and does not include amounts with special symbols such as $
let formatMount = function(money) {
letIt is used to splice decimal placesif (money === null) {
money = '0'
}
if (money.indexOf('. ') > 0) {// Process decimal cents = '.${Number(money).toFixed(2).split('.')[1]}'// If there is a decimal place, fetch the decimal place such as 23.45, then it will be.45}else {
cents = 00 '. 'Math.floor(money); // Add.00} money = math.floor (money)' '+ money.) replace (/ ((\ d {1, 3})? =(\d{3})+(? : $| \.) )/g,'$1')
returnMoney + cents} // Data is usually requested from the background. In most cases, the data is represented as a character, so you see arguments as string formatMount('256'256.00 formatMount) / / ('2564') / / 2564.00 formatMount ('256.1'256.10 formatMount) / / ('256.178'256.18 formatMount) / / ('123456') / / 123456.00 formatMount ('1234567'FormatMount (null) // 0.00Copy the code
Data sent from the background may be null. If this situation is not handled, an error will be reported