parseInt VS parseFloat

Benchmark created by Brian Blakely on


Description

Exactly what the name says. Finally, the gloves are off.

VERDICT! Use parseFloat, always, unless you're trying to actually grab the integer value out of a floating-point string.

Test runner

Ready to run.

Testing in
TestOps/sec
parseInt (Integer)
parseInt("123px");
ready
parseFloat (Integer)
parseFloat("123px");
ready
parseInt (Float)
parseFloat("123.123px");
ready
parseFloat (Float)
parseFloat("123.123px");
ready
Round and parseFloat (Float)
Math.round(parseFloat("123.123px"));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.