skip to Main Content
BigInt(9223372036854775807) //9223372036854775808n

I dont often work with large numbers so forgive me if this is a dumb question, but why is this not 9223372036854775807n?

Im expecting BigInt(9223372036854775807) //9223372036854775807n

3

Answers


  1. In javascript the BigInt is defined as 64 bit data type, which ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. So when you’re trying to operate on 9223372036854775807, it exceeds the limits and hence displays unexpected behaviour.

    You can refer to https://www.tutorialspoint.com/what-is-javascript-s-highest-integer-value-that-a-number-can-go-to-without-losing-precision for better understanding.

    Login or Signup to reply.
  2. If you want a BigInt with a value of 9223372036854775807, you should explicitly specify the n suffix to indicate that it’s a BigInt:

    const mpliang = 9223372036854775807n;
    
    Login or Signup to reply.
  3. console.log(9223372036854775807)//9223372036854776000
    
    
    console.log(BigInt(9223372036854776000))
    
    console.log(BigInt(9223372036854776000) === 9223372036854775808n)
    
    
    console.log(BigInt(9223372036854775807) === 9223372036854775808n)
    
    
    console.log(BigInt("9223372036854775807") )//expect

    9223372036854775807 is Number,It’s already inaccurate.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search