0

I'm having some issues with my code when calling a function from another script. When I send the data over the variable adds a 1. Is there away to get the value from the last 2 digits and remove 1 from them and then merge them into the main int again?

Where I'm calling the function: (test.js):

cards.getcards(76561198089544929, function(err, res, body){});

Inside the script with the fucntion (index.js):

exports.getcards = function(steamid, callback){
console.log(steamid);
}

Output: 76561198089544930

FIX

        var steamid = 76561198089544930; //This is what I got from the function.
        var toText = steamid.toString(); //convert to string
        var lastChar = toText.slice(-2); //gets last character
        var baseChars = toText.slice(0, -2);
        var lastDigit = +(lastChar); //convert last character to number
        var newlast = lastDigit - 1;
        var steamid = baseChars+newlast;
        alert(steamid);

1 Answers1

1

That number is too big to fit inside a javascript Number object. You have three choices here. Either use a string to store the number, or use a library to get arbitrarily precisioned numbers, or simply make the number smaller.

Edhi7
  • 26
  • 1
  • You are wrong. There is another option: var toText = steamid.toString(); //convert to string var lastChar = toText.slice(-2); //gets last character var baseChars = toText.slice(0, -2); var lastDigit = +(lastChar); //convert last character to number var newlast = lastDigit - 1; var steamid = baseChars+newlast; – Olle Thunberg Jun 17 '18 at 16:30