我有一个格式化十进制值的任务。我有一个文本框。用户可以输入不同的值。例如 - 如果它是 5 位数字 1,00,00 如果它是 6 12,12,33 像这样..我怎样才能动态地做到这一点?
function ReplaceNumberWithCommas(yourNumber) {
//Seperates the components of the number
var components = yourNumber.toString().split(".");
//Comma-fies the first part
components [0] = components [0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}