0

Somehow I got all my numbers to save with 00 at the end. I thought I could just divide by 100 but that does not work. It always prints 1 number off. The number I am using is: 983037730529353700. I did 983037730529353700/100 and get 9830377305293538 not 9830377305293537. Any help is useful!

  • 1
    Does this answer your question? [How to deal with floating point number precision in JavaScript?](https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript) – Elias Soares Jun 14 '22 at 21:56
  • No, this is a id an the number is saved with 2 extra 0s on the end and I need to remove them – Thebeston123 Jun 14 '22 at 22:00
  • 1
    Use substr instead. Dont use integer to store ids, use strings. – Elias Soares Jun 14 '22 at 22:05
  • If these are snowflakes, removing the last two digits won't work. There are no added digits there, the original number's last two digits became zeroes. You need to make sure you store these as strings, not as numbers. Also, take a look at [this](https://stackoverflow.com/questions/68230554/discord-displays-deleted-role-while-the-role-is-still-avalible/68230683#68230683) and [this](https://stackoverflow.com/questions/70732419/fetching-a-guild-using-its-id-returns-every-available-guild-in-discord-js/70733075#70733075) – Zsolt Meszaros Jun 15 '22 at 05:21

1 Answers1

0

You can use substring() function or slice() function, to remove the 2 extra 0s on the end. To do it:

Using substring() function:

if(!args[0]) { //Preventing for an error if args[0] not given
  const embed = new MessageEmbed()
  .addField("To use these command, type:", `${prefix} <Some kind of ID>`)
  .setTimestamp()
  .setColor('RANDOM')

  message.channel.send({embeds: [embed]})
} else {
  var str = args[0];
  str = str.substring(0, str.length - 2);
  message.channel.send(`${str}`)
}

Test Image Here using Substring

var str = "983037730529353700";

str = str.substring(0, str.length - 2);

console.log(str)

Using slice() function:

if(!args[0]) {
  const embed = new MessageEmbed()
  .addField("To use these command, type:", `${prefix} <Some kind of ID>`)
  .setTimestamp()
  .setColor('RANDOM')

  message.channel.send({embeds: [embed]})
} else {
  var str = args[0];
  str = str.slice(0, -2);
  message.channel.send(`${str}`)
}

var str = "983037730529353700";
str = str.slice(0, -2);
console.log(str)

Test Image Here using slice

新Acesyyy
  • 1,152
  • 1
  • 3
  • 22