当我开始在htPrice字段中写入时,Nan出现在ttcPrice字段中,我该如何解决这个问题?
calculatTTC() {
const htPrice = parseFloat(this.htpriceTargets[0].value);
const tvaPercent = parseFloat(this.tvaTargets[0].value);
const ttcPrice= parseFloat(preTaxPrice + vatPercent);
if (isNaN(htPrice) && isNaN(tvaPercent)) {
this.ttcPriceTargets[0].value = 'the value is not correct';
} else {
this.ttcPriceTargets[0].value = ttcPrice;
}
}
您应该检查htPrice或tvaPercent是否为NaN。如果两者都不存在,则计算TTC
calculatTTC() {
const htPrice = parseFloat(this.htpriceTargets[0].value);
const tvaPercent = parseFloat(this.tvaTargets[0].value);
if (isNaN(htPrice) || isNaN(tvaPercent)) {
this.ttcPriceTargets[0].value = 'the value is not correct';
} else {
const ttcPrice= parseFloat(preTaxPrice + vatPercent);
this.ttcPriceTargets[0].value = ttcPrice;
}
}