decimal.js icon indicating copy to clipboard operation
decimal.js copied to clipboard

Bigint support

Open protango opened this issue 4 years ago • 5 comments

With bigint now a part of JavaScript, it would be nice for Decimal.JS to support it within its constructor and operations.

As a workaround we can just convert bigint's to strings before using them in Decimal.JS, however this becomes very repetitive with lots of numbers.

protango avatar Jul 10 '21 03:07 protango

Any news?

mahnunchik avatar Aug 16 '22 09:08 mahnunchik

@mahnunchik

No news. I'll try and have a look at this soon.

MikeMcl avatar Aug 17 '22 20:08 MikeMcl

Would you accept a PR which treats BigInt as a string in the constructor? Should be pretty simple to do around here:

if (t === 'bigint') {
  v = v.toString();
  t = 'string';
}

sterlu avatar Jul 05 '23 10:07 sterlu

@sterlu

Yes, but if the argument is a BigInt then there would be no need for the minus and plus sign checks, or for the isDecimal.test(v), so it would just be a matter of setting x.s to 1 or -1 depending on whether the argument is positive or negative, and then returning parseDecimal(x, v.toString()). Ça va?

MikeMcl avatar Jul 05 '23 16:07 MikeMcl