parseInt expects parsing of the string argument, so it converts it to string first.
1/1000000 when converting to the string "0.000001" , parseInt then ignores everything starting with "." since it is intended only for integers, so it reads it as 0 .
1/10000000 so small that converting it to a string uses the scientific notation "1e-7" , parseInt then ignores everything starting with "e", since it is only for integers, so it reads it as 1 .
Basically, parseInt is simply not what you should be doing.
To convert a number to an integer, OR it is from 0, since any bitwise operation in JavaScript forces the number to a 32-bit int, and ORing from 0 does not change the value that goes beyond:
>(-1/10000000)|0 0 >1234.56|0 // truncation 1234 >(2147483647+1)|0 // integer overflow -2147483648
Boann source share