0

Why in JS 1000000000000000000000000000001%10 equals to 6?
I try it with calculator, it shows that mod is equal to 1.

I couldn't find any information on the Web. So could someone answer for this question?

console.log(1000000000000000000000000000001 % 10);          
ankushlokhande
  • 870
  • 5
  • 20
mrkzh
  • 11
  • 2
    Number is too big to represent accurately. Use BigInt instead. – kelsny Mar 31 '23 at 13:50
  • Your number exceeds the representational capacity of a JavaScript number. – Pointy Mar 31 '23 at 13:50
  • see: [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) also `%` in javascript is the remainder operator not the modulus – pilchard Mar 31 '23 at 13:51
  • 1
    `1000000000000000000000000000001n % 6n` will work. – trincot Mar 31 '23 at 13:53

0 Answers0