PDA

View Full Version : how to sum up numbers



salih
9 Sep 2010, 4:09 AM
when i try to add 2 numbers like

var sum=0;
var count1=0;


sum+=count;
the values are getting appneded

9 Sep 2010, 11:42 AM
when i try to add 2 numbers like

var sum=0;
var count1=0;


sum+=count;
the values are getting appneded

what?
http://tdg-i.com/img/screencasts/2010-09-09_1538.png

9 Sep 2010, 11:44 AM
By the way, this is a basic JavaScript question, not an Ext JS one.

http://oreilly.com/catalog/9780596527464
http://programmers.biz/wp-content/plugins/wp-o-matic/cache/549c9_learningJavascript.jpg

Condor
10 Sep 2010, 1:30 AM
the values are getting appneded

Are you sure your variables are numbers and not strings?

sideeque
10 Sep 2010, 11:15 AM
Try like below.


var sum=0;
var count1=0;


sum= Number(sum) + Number(count);

Condor
10 Sep 2010, 11:24 AM
Try like below.

That's not a good example.

This would be:

var sum = '0';
var count1 = '0';
sum = Number(sum) + parseInt(count1, 10);

darthwes
10 Sep 2010, 11:25 AM
Unary plus is integer conversion.

i.e.


var a = "1";
var b = "2";
var c = a + b; //"12"
var d = (+a) + (+b); //3

salih
12 Sep 2010, 8:08 PM
Thanks every body...Isssue Resolved ;)

sum=parseInt(sum)+parseInt(cntcount);