BluLotus
BluLotus

Reputation: 159

I am trying to convert a javascript Number type to a BIGINT to be passed to a Postgres table

I have a BIGINT I need to store in a Postgres table. I am using a rest API and have no issue passing in the javascript Number type on row creation but when I try and update it I get this error:

 "Error: invalid input syntax for integer: \"\" 

Is there a way to cast this type? I tried using math.js with no luck so far. Any suggestions or help would be appreciated.

Upvotes: 0

Views: 3875

Answers (1)

mattdaspy
mattdaspy

Reputation: 882

Try this and see :

const string = 'YourNumberHere';
BigInt(string);

Using Math.js :

var reqId = "YourNumberHere";
var myBigNumber = math.bignumber(reqId);
var res = math.add(myBigNumber, 1);
console.log(myBigNumber.toString());
console.log(res.toString());

You can use a JavaScript lib called BigInteger.js for the purpose.it is an arbitrary-length integer library for Javascript, allows arithmetic operations on integers of unlimited size, notwithstanding memory and time limitations.This lib can be download from this link.

Like var largeNumber = bigInt("75643564363473453456342378564387956906736546456235345");

You can find documentation of this lib HERE

Upvotes: 2

Related Questions