Backgrounds
1 | parseInt(0.0000005) |
Explanations
parseInt
accepts string as the first argument, represents the value to parse. If this argument is not a string, then it is converted to one using the ToString
abstract operation.
In JavaScript, the number which has more than 6 zeros in front of the first non-zero digit will be displayed in scientific notation, specified by ECMA . That means , 0.00000005.toString()
will return '5e-7'
So, the code above can be explained as following:
1 | 0.0000005.toString() |
Extra
What about postive numbers ?
1 | parseInt(5e7) |
Tips
parseInt
should not be used as a substitute for Math.floor()