微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我正在建立一个应该包含小数点的数字,以便在计算中使用,我在哪里出错?

如何解决我正在建立一个应该包含小数点的数字,以便在计算中使用,我在哪里出错?

我已经创建了一个功能,该功能应该为我建立号码,该号码正在运行,并且由于某种原因已停止。

function buildNumber(num){
    console.log(num);
    if (calcState === true && currentNumber.toString().length < 9){
        if(currentNumber === 0){
            if (num === "."){
                currentNumber = Number(`${currentNumber}${num}`);
                console.log(currentNumber);
                checkDecimal = true;
                updatedisplay();
            } else if (num >=0 && num <= 9) {
                currentNumber = num;
                console.log(currentNumber);
                updatedisplay();
            }

        } else {
            if (num === "."){
                currentNumber = Number(`${currentNumber}${num}`);
                checkDecimal = true;
                console.log(currentNumber);
                updatedisplay();
            } else if (num >=0 && num <= 9) {
                currentNumber = Number(`${currentNumber}${num}`);
                console.log(currentNumber);
                updatedisplay();
            }
        }
    }
}

事件监听器的触发方式如下:

pointBtn.addEventListener("click",function(){
    console.log("Decimal pressed")
    if (checkDecimal === false){
        buildNumber(".");
    }
});

我只是不知道为什么它没有触发,buildNumber()内的console.log显示了当我单击按钮时该值在那里,它根本不执行我原来的操作它在做。我错过了什么明显的东西吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。