parseInt and parseFloat should parse strings and convert them to Number s. So, when you pass them a Number , it gets a forced interpretation. So, at least in Firefox, "" + 1e+20 displays "100000000000000000000" , and "" + 1e+21 displays "1e+21" .
Let's read the parseInt documentation :
If parseInt encounters a character that is not a digit in the specified radius, it ignores it and all subsequent characters and returns an integer value processed to this point
therefore parseInt("1.whatever") returns 1 and parseInt("32.231e+something") returns 32.
A similar thing should happen with parseFloat .
This is a weak input error. IMO the correct behavior when doing what you are doing is an exception.
source share