我收到错误TS2345:“数字”类型的参数无法分配给“字符串”类型的参数

时间:2019-09-07 22:40:58

标签: angular typescript angular7

我有以下代码并出现TS2345错误。我已经使用过Angular 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);

1 个答案:

答案 0 :(得分:1)

可以删除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