Khush Patel
Khush Patel

Reputation: 31

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

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

Upvotes: 2

Views: 936

Answers (1)

skovy
skovy

Reputation: 5650

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

Upvotes: 1

Related Questions