How can I stop rounding int values in MySQL

Viewed 175

I am a discord bot developer. I am trying to use MySQL for my discord bot. I am trying to save guild ids in my table. Guild ids rounding automatically when I post to table. Forexample my guild id is 837465019283745861. It is posting like 837465019283745900. I am using mysql module.

My Table:

CREATE TABLE guilds (
id INT PRIMARY KEY AUTO_INCREMENT,
guild_id BIGINT(18) NOT NULL);

My Post Code:

const guild = 837465019283745861;
connection.query('INSERT INTO guilds (guild_id) VALUES (?)', guild, function(error, results, fields) {
    if (error) throw error;
    console.log('Data sent!');
});
2 Answers

Those values don't get rounded in MySQL. That's JavaScript screwing with you because you're not using BigInt:

const guild = 837465019283745861n;

All numbers in JavaScript are actually floating point unless otherwise specified. This leads to rounding on larger numbers.

Related