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


#1

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.


#2

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

maybe this will help!


#3

Hello,
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


#4

+1. Most important fact here.