How to assign a variable type to variables in an object
Here is the code
var m = new Object();
m.p1 = 37.7;
m.p2 = 37.7;
...
function addSubtract(pn){
switch (pn) {
case 1:
var amt = prompt("Enter a value");
if (amt != null)
{
m.p1 += amt;
}
break;
}
}
Basically when I enter 1, the value of m.p1 becomes 37.71 instead of 38.7
Then I enter 1.0 and it shows 37.711.0. I figured out it is doing
concatenation rather than addition. I tried to find a way to declare the
type but I can't figure out how to use it in a variable in an object.
I am more of a C++ person and there is something obvious that I'm missing
here. I just can't find it on Google.
So do I have to assign it a type or is there another way to force an
arithmetic addition?
No comments:
Post a Comment