/    Sign up×
Community /Pin to ProfileBookmark

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;

etc.etc.

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. ?

    to post a comment
    JavaScript

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @mrhooMar 19.2007 — As javascript only allows numbers up to 17 digits [/QUOTE]
    You are mistaking javascript integers for numbers-

    javascript allows numbers up to +-10e302.

    Look into Math.pow and String.toExponent to handle large numbers.
    Copy linkTweet thisAlerts:
    @ClarkycatauthorMar 19.2007 — Thanks! Just had a look and found what I needed in seconds!

    Thanks as well for the speedy reply ?
    ×

    Success!

    Help @Clarkycat spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.27,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...