I am trying to find the sum of one column's timings which is like '00:00:00' format. I am splitting the time string at ':' and storing into an array. Then trying to add array1[1] value to array2[1] value. Here I'm not getting t开发者_C百科ype casting logic. I'm getting an error when I give int(array2[1]) += int(array1[1])
.Any help is greatly appreciated!
parseInt(string)
converts string to int (returns 0 on failure).
You probably should cast your array elements using parseInt()
before trying to add them. Create a function for that:
private function addFromString(a:String, b:String) : Number {
return parseInt(a,10) + parseInt(b,10);
}
You can check whether a
and b
are NaN to make it better.
Then just do
addFromString(ary1[1], ary2[1])
精彩评论