<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> /** * 格式化money,(123456=>123,456.00) * num:string or number */ formatMoney = (num) => { var end = parseFloat((num/100).toFixed(2)).toLocaleString(); if(end.indexOf(‘.‘)==-1){ end+=‘.00‘; } return end; } console.log(formatMoney(1234898.232)) /** * 格式化银行卡 或者订单号(四位一隔开) * bank(String) */ formatBank = (bank) => { return bank.replace(/[\s]/g, ‘string‘).replace(/(\d{4})(?=\d)/g, "$1 "); } console.log(formatBank(‘1232398989898‘)); </script> </body> </html>