SoFunction
Updated on 2025-04-09

Ideas for implementing JS's Milloqualitative Algorithm


function commafy() {
var num = ("NumA").value;
//1. Remove the space first and determine whether it is empty and non-number
num = num + "";
num = (/[ ]/g, "");
if (num == "") {
alert("null value, end");
return;
}
if (isNaN(num)) {
alert("non-number, end");
return;
}
//2. Depending on whether there are decimal points, we will deal with the situation in different situations
var index = (".");
if (index==-1) {//No decimal points
var reg = /(-?\d+)(\d{3})/;
while ((num)) {
num = (reg, "$1,$2");
}
} else {
var intPart = (0, index);
var pointPart = (index + 1, );
var reg = /(-?\d+)(\d{3})/;
while ((intPart)) {
intPart = (reg, "$1,$2");
}
num = intPart +"."+ pointPart;
}
return alert(num);
}