I have just observed that the parseInt
function doesn't take care about the decimals in case of integers (numbers containing the e
character).
Let's take an example: -3.67394039744206e-15
> parseInt(-3.67394039744206e-15)
-3
> -3.67394039744206e-15.toFixed(19)
-3.6739e-15
> -3.67394039744206e-15.toFixed(2)
-0
> Math.round(-3.67394039744206e-15)
0
I expected that the parseInt
will also return 0
. What's going on at lower level? Why does parseInt
return 3
in this case (some snippets from the source code would be appreciated)?
In this example I'm using node v0.12.1
, but I expect same to happen in browser and other JavaScript engines.
-3.67394039744206e-15.toFixed(19)
-- what exactly is that doing?(-3.67394039744206e-15).toFixed(19)
returns a different result. – Godparent-3.67394039744206e-15.toFixed(19)
is the same as-((3.67394039744206e-15).toFixed(19))
and the-
(like+
) implicitly converts it into a number (it’s like a shorthand forNumber()
, e. g.+'14'
is14
and-'14'
is-14
). – Relativityobj.a-obj.b
would result inReferenceError: a is not defined
or something like that… – RelativityparseInt(-3.67394039744206e-15) === -3
? – Funest