Just the other day, I was successfully converting strings to numbers with no issues. However, today things have taken a turn for the worse. Even after committing my changes thinking all was well, I now find that when attempting to cast in different ways, I end up with NaN. It's as if something is affecting the variable where I store the casted values (because they appear fine when logged with console.log) – so what could I possibly be doing wrong?
Here's the code snippet:
totalPrice: number;
total: number;
if (this.cart_articles) {
for (let article of this.cart_articles) {
this.totalPrice += parseFloat(article.price);
console.log(this.totalPrice);
console.log(parseFloat(article.price));
}
this.total = this.totalPrice + (this.totalPrice * 0.18);
this.iva = this.totalPrice * 0.18;
}
Despite logging the values before assignment and seeing them being correctly casted, the variables total, totalPrice, and iva all end up as NaN. How can I go about resolving this issue? Apologies, but it's clear that I'm still quite new to all of this.