You can create a function to format number like the following:
function numberFormatter(n){ n = (Math.round(n * 100) / 100).toFixed(2).toString().replace(/\\B(?=(\\d{3})+(?!\\d))/g, ","); return n.split('.')[1] == 0 ? n.split('.')[0] : n; } console.log(numberFormatter(800000)) console.log(numberFormatter(1000.25)) console.log(numberFormatter(1000.254)) console.log(numberFormatter(1000.255))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.