I have a function having following lines:
payementReceived=data.toJSON().total;
paymentTotal=$("#paymentTotal").html();
console.log(typeof(parseInt(paymentTotal)));
console.log(typeof(parseInt(paymentReceived)));
console.log(parseInt(paymentTotal)-parseInt(paymentReceived));
I get the following in console
number
number
NaN
i don't understand if both are numbers then why it isn't able to give the proper substraction result.
new Number(), not justNumber(). Or rather -parseInt(xxx, 10)typeof(NaN) === "number"NaNvalue is of typenumberas well?paymentTotalandpaymentReceived?parseInt, you should always include10as a second parameter (otherwise numbers starting with a 0 will be read as base 8!)