parseFloat w/tofixed vs. Math.round vs bitwise floor (v11)

Revision 11 of this benchmark created on


Description

Compare each of them as function. Get two digit after decimal point, from a string.

Setup

var str = "1.23456";
    _floor = function(n){ return ~~(n * 100)/100; };
    _dec = function(n){ return Math.round(n * 100) / 100; };

Test runner

Ready to run.

Testing in
TestOps/sec
Math.round
n = _dec(str);
 
ready
parse Float toFixed
n = parseFloat(str).toFixed(2);
 
ready
bitwise floor
n = _floor(str);
 
ready

Revisions

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