-
Notifications
You must be signed in to change notification settings - Fork 743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revive BigNumber from being serialized to plain object #245
Comments
An BigNumber.prototype.toFormat.call(
new BigNumber({"s":1,"e":3,"c":[8212,89000000000000], _isBigNumber: true})
);
// "8,212.89" new BigNumber({"s":1,"e":3,"c":[8212,89000000000000], _isBigNumber: true}).toFormat();
// "8,212.89" I don't think that the vast majority of users will want to be creating BigNumbers in this way and it is not something I want to encourage, so I am reluctant to add another method to the API. I only added this ability when requested becuase it was basically very simple and costless to do so. |
Hi Michael, thanks for a such quick reply! I didn't know about that Regards, |
@MikeMcl BigNumber is converted to plain object and loses BigNumber prototype when |
@F3n67u same solution because the problem is same. |
Post the |
@ralekna @MikeMcl I use Native BigInt to solve the problem, bec window.postMessage support pass BigInt without lose it's type. In the occasion which require demical divide, I still use Big.js:
|
Hi,
there are some occasions when BigNumber is converted to plain object and loses BigNUmber prototype - for example when it is taken from
window.history.state
. In such situation it's a bit uncomfortable to make such object fully functional again. For examplewill raise an exception
TypeError: x.toFixed is not a function
becausetoFormat
function assumes thatthis
object is "normal"BigNumber
instance.Trying to pass that object to constructor also fails:
My suggestion (and feature request) would be to introduce static
.from()
method or modify constructor to accept such object.Regards
The text was updated successfully, but these errors were encountered: