This content has been marked as final. Show 6 replies
convert those strings to numbers using the Number() function.
Or better yet, really convert them to numbers using parseFloat() or you can use parseInt() if you know that you will only have integers.
Label3.text = parseFloat(Label1.text) + parseFloat(Label2.text);
There are times when I have seen casting as Number() fail to properly change the value to a number, even when it seems like it should work.
i've never had it fail. was it a white space issue that caused Number() to fail?
I think it has been more often when I was reading css, xml, or other external files, but it could also have been some kind of white space or special key at the end. In any event I just find it easier to always use parseInt/Float and not have to worry about it working.
I've never tested it for any kind of speed hit for anything that required a lot of operations, so there might be a savings there, but these types of things are usually fairly low performance in any event.
So for typing four more characters I feel I get a benefit. Plus you can use the second argument and convert to other bases if you need to!