I have been writing JavaScript for 13 years, but I kind of rediscovered it over the past few months as a way to write programs that can be used by anyone who visits a web page without installing anything. For example, http://ab1jx.webs.com/calcs/calcs.html .
I recently discovered that since JavaScript was freely printed by design, it continues to concatenate strings when I want them to add numbers. And this is unpredictable. One routine worked fine for several days, and then when I fed different data into it, the problem succeeded, and I ended up with an incredibly large number.
Sometimes I was lucky if it interfered with ( )
for one term, sometimes I had to resort to parseInt()
or parseFloat()
for one term. This reminds me a bit of trying to force a float result in C by putting a.00 on one (constant) term. I just did this when I tried +=
something from an array that I was already loading, doing parseFloat()
for everything.
Is this just happening? If I use parseInt()
or parseFloat()
for at least one of the terms every time I add, will this prevent this? I use Firefox 6 under Linux for recording, but portability between browsers is also a concern.
ab1jx source share