Adding strings instead of numbers
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.
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".
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.
Look into Math.pow and String.toExponent to handle large numbers.
Thanks! Just had a look and found what I needed in seconds!
Thanks as well for the speedy reply
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)