I have just observed that the parseInt
function doesn\'t take care about the decimals in case of integers (numbers containing the e
character).
parseInt
has the purpose of parsing a string and not a number:
The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).
And parseInt
calls the function ToString
wherein all the non numerical characters are ignored.
You can use Math.round, which also parses strings, and rounds a number to the nearest integer:
Math.round("12.2e-2") === 0 //true