change string to int

admin

Administrator
Staff member
// I have two strings:
var first = "123px";
var second = "345px";

// I substring them to remove the "px"
var first = first.substring(0,first.length-2)
var second = second.substring(0,second.length-2)

// Now I want to get the result of them two together, namely 864
var mySum = first+second

// The problem is that first and second are being treated as strings and not integers, so the mySum is 123456 in this case.

Any thoughts?
// Michelle
 
Back
Top