angular - 我收到错误 TS2345 : Argument of type 'number' is not assignable to parameter of type 'string'

标签 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);

最佳答案

你能去掉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

关于angular - 我收到错误 TS2345 : Argument of type 'number' is not assignable to parameter of type 'string' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57837937/

相关文章:

css - 如何使Angular的<router-outlet>与CSS Grid一起使用

javascript - Angular 构建结果破坏了 html 实体,如何防止这种情况发生

angular - 如何使用 Angular 检测浏览器?

node.js - 要求 ts-node 和 ts-node/register 有什么区别

typescript - 从组件打开 ng-bootstrap 模态

angular - 对 XMLHttpRequest 的访问已被 CORS 策略阻止

angular - 我需要通过路由器导出激活方法在路由器导出中获取组件名称

javascript - 在 AJAX 调用成功响应时将数据推送到数组中会导致多次附加最后一个数据

rest - Angular 2 REST 请求 HTTP 状态代码 401 更改为 0

Angular 5 ng-repeat 实现