4 ms·
People will convert a float to an integer by using parseInt. That function automatically converts its argument to a string, then parses it as an int, ignoring
by ErikCorry 4y ago
People will convert a float to an integer by using parseInt. That function automatically converts its argument to a string, then parses it as an int, ignoring anything after the decimal point.
Completely fails for a number big enough to be stringified to 1.34e20.
Plot twist, if your number is in a reasonable range this is very fast because there was one a popularJS benchmark that did this.