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

Support for BigInt?

Open shaunhurley opened this issue 3 years ago • 2 comments

Hey folks, curious to understand what (if any) plans you have for supporting the bigint type?

I'm migrating some code to use the latest Square SDK and noticed that they are now returning all numbers as bigint, and creating a currency from a bigint results in a $0.00 value.

currency(100).format() --> $1.00 currency(100n).format() --> $0.00

shaunhurley avatar May 04 '22 17:05 shaunhurley

When this library was first created, BigInt wasn't widely supported across all browsers - but that has certainly changed.

There's some considerations to be made because we'd either have to support BigInt internally, or truncate to the max integer, which negates some of the benefits from using BigInt. I would certainly thing supporting this in the future could be a possibility though.

scurker avatar May 04 '22 18:05 scurker

I figured as much, and it's not even that there is necessarily a need to work with numbers that big, just that it's becoming more common for source data to be returned in that (bigInt) format - Square (my case in question) is very widely used, for example.

In the short term, since bigInt's stringify to a usable integer (within the bounds of discussions), I am able to resolve my issues by making my current calls with a .toString() on the end of the values. That might be sufficient as a short term (non-breaking) fix for the interim.

shaunhurley avatar May 04 '22 20:05 shaunhurley