Results 1 to 8 of 8

Thread: how to sum up numbers

  1. #1
    Ext User
    Join Date
    Aug 2009
    Posts
    20

    Default how to sum up numbers

    when i try to add 2 numbers like

    var sum=0;
    var count1=0;


    sum+=count;
    the values are getting appneded

  2. #2
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    Quote Originally Posted by salih View Post
    when i try to add 2 numbers like

    var sum=0;
    var count1=0;


    sum+=count;
    the values are getting appneded
    what?

  3. #3
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    By the way, this is a basic JavaScript question, not an Ext JS one.

    http://oreilly.com/catalog/9780596527464

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Quote Originally Posted by salih View Post
    the values are getting appneded
    Are you sure your variables are numbers and not strings?

  5. #5
    Sencha User sideeque's Avatar
    Join Date
    Aug 2009
    Location
    Washington DC
    Posts
    50

    Default

    Try like below.

    Code:
    var sum=0;
    var count1=0;
     
     
    sum= Number(sum) + Number(count);

  6. #6
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Quote Originally Posted by sideeque View Post
    Try like below.
    That's not a good example.

    This would be:
    Code:
    var sum = '0';
    var count1 = '0';
    sum = Number(sum) + parseInt(count1, 10);

  7. #7

    Default

    Unary plus is integer conversion.

    i.e.
    Code:
    var a = "1";
    var b = "2";
    var c = a + b; //"12"
    var d = (+a) + (+b); //3
    Wes

  8. #8
    Ext User
    Join Date
    Aug 2009
    Posts
    20

    Default Resolved

    Thanks every body...Isssue Resolved

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

Similar Threads

  1. How create the row SUM
    By wertyk in forum Ext 2.x: Help & Discussion
    Replies: 17
    Last Post: 15 Nov 2011, 3:24 AM
  2. How to sum widths and paddings?
    By lucazav in forum Ext: Q&A
    Replies: 4
    Last Post: 15 Jan 2010, 1:18 AM
  3. Sum at the Grid Bbar
    By dyjathan in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 12 Nov 2009, 8:01 PM
  4. Count sum from grid
    By nahawand in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 27 Apr 2009, 7:59 AM
  5. sum over all groups
    By ajez in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 11 Feb 2008, 2:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •