Argument of type 'number' is not assignable to parameter of type 'string'

I have the below calculation on my code, but it showing type conversion error.
let gold_kg_rate: any = parseFloat((((((parseFloat(data['SPOT-GOLD']['ask']) + parseFloat(rpdifference.premium))*parseFloat(gold_ozt))*parseFloat((inr+rpdifference.inrpremium)))+parseFloat(rpdifference.custom))*((100 + parseFloat(rpdifference.bank_vat)) / 100)).toFixed(2));
Could you please help anyone to fix this issue. While I build to production this error occur.

let num = 3;//number
var stringForm = num.toString();

maybe this will help!


hmmmm. Is this a readable and maintainable formula? I think not.

I suspect , that gold_kg_rate should be a number. Maybe inr+rpdifference.inrpremium one of them is a string or …

Imho you should take out the parse stuff out of the formula and store it in properties with correct declarations. use then this properties for calculations and better maintainabillity.

Best regards, anna-liebt

1 Like

+1. Most important fact here.

1 Like

Did you solve this problem, I have the same…

you can use
(+data[‘SPOT-GOLD’][‘ask’] + + rpdifference.premium * +gold_ozt).toString() must solve the issue

@AgenciaFeeshop you need to provide your code with declarations, when you wanna help…
But you can easily help your self.

If you have the same error, then you wanna calculate a number and a string together. You need to convert the string first to a number.

To do this in a maintainable way you should never use any.
Declare all parts of your formula as bla: number, blubb: number.
Never do type conversion inside formula.
Use editor that show you the place of fault, where you wanna calculate strings with numbers.

Best regards, anna-liebt