我有以下代码,得到TS2345错误。我用了角7。

let totalAmount = quantity*rate;
let discountAmount = totalAmount - (totalAmount*discount)/100;
let finalValue = parseFloat(discountAmount - (discountAmount - (discountAmount * (100/(100+tax))))).toFixed(2).toString();
taxableAmount.setValue(finalValue);

最佳答案

你能把parseFloat去掉吗?parseFloat需要一个字符串作为参数,但您传递的是一个number

let totalAmount = quantity * rate;
let discountAmount = totalAmount - (totalAmount * discount) / 100;
let finalValue = (
  discountAmount -
  (discountAmount - discountAmount * (100 / (100 + tax)))
)
  .toFixed(2)
  .toString();

TypeScript playground

10-06 04:30