SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Summing numbers in the -10,000,000 range.

    I am summing numbers in the -10,000,000 range (the data does not have commas).

    I am getting "NaN" for a result.

    Is there any way of displaying the result and make calculations with the sum?

  2. #2
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Answer me this. What are the reasons for a "NaN" result?

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Philosophaie View Post
    I am summing numbers in the -10,000,000 range (the data does not have commas).

    I am getting "NaN" for a result.

    Is there any way of displaying the result and make calculations with the sum?
    There sure is - what code are you currently using?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Philosophaie View Post
    Answer me this. What are the reasons for a "NaN" result?
    NaN means Not A Number, which can result from trying to add together non-numbers, such as undefined + 10;

    Code javascript:
    var total; // undefined
    total += 10; // total is now NaN

    It's best to assign a default value, in such cases.

    Code javascript:
    var total = 0; // default value of 0
    total += 10; // total is now 10
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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