添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I get error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'

Ask Question

I have following code and get TS2345 error. I have used 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);

Can you remove the parseFloat. parseFloat expects a string as the argument but you're passing a number,

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

TypeScript playground

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.