Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numbers adding next to each other (ex. 123 + 123 = 123123)

So I have like kind of a homemade economy thing and when I added a working command and when it works it picks a random number and stuff but when it adds the number to the old currency it's adding like for ex 123+123 = 123123 when it supposed to be 246 I don't know how to fix this I tried everything and nothing has worked for me

    if (message.content.toLowerCase().startsWith(prefixS.prefix + 'work')) {
    const inventoryS = await inventory.findOne({ userID: message.author.id, guildID: message.guild.id });
    if (inventoryS.item1 === 'true') {
      const payment = Math.floor(Math.random() * 125) + 25;
      inventoryS.currency += payment
      inventoryS.save()
      message.channel.send({ embeds: [new Discord.MessageEmbed().setTitle('After a long day of work your balance is').setDescription(`__Your balance__\n > Money: ${inventoryS.currency}`).setColor('BROWN')] })
    }
    }
like image 299
itsmateo20 Avatar asked Oct 19 '25 18:10

itsmateo20


1 Answers

Both of them must be Numbers to do addition, otherwise it will add as strings

inventoryS.currency = parseInt(inventoryS.currency) + parseInt(payment)
like image 101
MrMythical Avatar answered Oct 22 '25 09:10

MrMythical