How to fix javascript .toFixed is not a Function error

toFixed() method formats a number. The current value is of type string and instead of arithmetic addition, string concatenation is happening. Convert those to number before adding:

Change:

var totalSum = (grandTotal + getShippingCost).toFixed(3);

To

var totalSum = (Number(grandTotal) + Number(getShippingCost)).toFixed(3);

Leave a Comment