当 number1 和 number2 为 NaN 或 0 时,如何隐藏/不打印/输出,只需修改以下内容
document.getElementById('inputTextToSave').innerHTML = parseFloat(number1).toFixed(3) + "," + parseFloat(number2).toFixed(3);
最佳答案
var n1 = parseFloat(number1),
n2 = parseFloat(number2),
list = [];
// add values to array if they're not NaN or > 0
if (n1) {
list.push(n1);
}
if (n2) {
list.push(n2);
}
// combine values into a string separated with commas
document.getElementById('inputTextToSave').innerHTML = list.join(",");
关于Javascript 数组不打印/输出 NaN 或 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44216960/