How to add two strings as if they were numbers? [duplicate]

I have two strings which contain only numbers:

var num1 = '20',
    num2 = '30.5';

I would have expected that I could add them together, but they are being concatenated instead:

num1 + num2; // = '2030.5'

How can I force these strings to be treated as numbers?

20 Answers
20

Leave a Comment