Skip to content
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

15 Significant digit limit #14

Closed
Xotic750 opened this issue Sep 29, 2013 · 3 comments
Closed

15 Significant digit limit #14

Xotic750 opened this issue Sep 29, 2013 · 3 comments

Comments

@Xotic750
Copy link
Contributor

I was wondering why the number type input is limited to 15 significant digits when Javascript can represent an integer to 16?

Ie. -9007199254740991 to 9007199254740991

    // Disallow numbers with over 15 significant digits if number type.
    if ( isNum && b > 15 && n.slice(i).length > 15 && +n.slice(i) > 9007199254740991) {

        // 'new BigNumber() number type has more than 15 significant digits: {n}'
        ifExceptionsThrow( orig, 0 )
    }

I'm not suggesting this is the fix/enhancement as I'm sure there is more to it than that.

@MikeMcl
Copy link
Owner

MikeMcl commented Sep 30, 2013

Yes, I discussed this in #11.

Basically, with double precision values there is no guarantee that decimal numbers with sixteen significant digits or more will be represented precisely. For example,

console.log( 823456789123456.3 );    // 823456789123456.2

In any case, the 15 s.d. limit can be turned off with

BigNumber.config({ ERRORS: false });

@Xotic750
Copy link
Contributor Author

Thanks for that, don't know how I missed it.

I don't particularly want to turn off the error, it will come in very useful, but what I had hoped is that if I enter the value as a string ("9007199254740991") rather than a number type (9007199254740991) then I wouldn't experience the error. That is what you also seem to suggest in the other thread, but it does not work for me, perhaps I am missing something else?

@Xotic750
Copy link
Contributor Author

Ok, it must be something that I am doing locally in my app, as it works in a jsfiddle without the rest of my code. Thanks once again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants