Results 1 to 3 of 3

Thread: Adding strings instead of numbers

  1. #1
    Join Date
    Mar 2007

    Question Adding strings instead of numbers

    Hi there

    I'm trying to work out a function which will enable me to add together many very large numbers.

    As a quick explanation of its use - I currently work on several mod projects for different games, and i've scripted a crafting system that works by adding together substrings found on particular items in order to generate the resulting item.

    Anyway, i'm looking to do my first public release but I thought in order to speed up people's own creations using the system I could provide with it a webpage that could create the rather long and complex strings for them.

    As javascript only allows numbers up to 17 digits (and I believe the biggest numbers in the system are 50+ digits long) I was looking for a way to add the strings together.

    Here is an example of what I mean -

    The items required for the system are listed with checkboxes next to them. Each carries its own unique value.

    item 1 = 1;
    item 2 = 10;
    item 3 = 100;
    item 4 = 1000;
    item 5 = 10000;


    I'm trying to come up with a way to add these values together as strings. In essence, instead of using addition I was hoping to find some way of using the strings length then simply replace() the appropriate character with a "1".

    The problems I could think of though, and that have prevented me from coding this myself (my javascript knowledge is pretty limited) -

    1. The resulting string must not be appended by zeros. However, obviously if a larger string is added to an existing string, then all the characters in the existing string must be pushed along. This was something I was unsure about - i.e testing between different lengths and acting accordingly.

    2. Storing the values of the checked items. In the game's system, you can only have a maximum of 8 items to create the resulting item (this is to stop the obvious flaw with this system). I'm unsure just how to store the values either in seperate vars or in an array, so that they can be removed and replaced easily should a checkbox be unchecked.

    I hope that gives you a good idea of what i'm trying to do. Any info at all, even a nudge in the right direction, would be most appreciated.

  2. #2
    Join Date
    Feb 2006
    As javascript only allows numbers up to 17 digits
    You are mistaking javascript integers for numbers-

    javascript allows numbers up to +-10e302.
    Look into Math.pow and String.toExponent to handle large numbers.

  3. #3
    Join Date
    Mar 2007
    Thanks! Just had a look and found what I needed in seconds!

    Thanks as well for the speedy reply

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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