Reputation: 561
It might seem as a trivial question, but I was not able to get any relevant results since google search is case insensitive.
Let's say I have following code:
items[5] = "5\,5"
totalAmount: number = 5
totalAmount = totalAmount + Number(items[5].replace( "\\,", "."));
and my IDE tells me that I cannot appy operands to type number and Number. When I serached for a method to turn string into a number, I was only met with the above solution, which is useless for me. How can I make a number typed variable from a string?
Upvotes: 0
Views: 184
Reputation: 26075
Don't see any issue with your code and it work fine for me in Visual Studio Code but try following code and see if it works for you:
totalAmount: number = 5
totalAmount = totalAmount + parseFloat(items[5].replace( "\\,", "."));
Upvotes: 1