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 type casting logic. I'm getting an error when I give int(array2[1]) += int(array1[1])
.Any help is greatly appreciated!
parseInt(string)
将字符串转换为int(失败时返回0)。
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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.