Rounding performance in JS (v2)

Revision 2 of this benchmark created on


Description

The 1st and 3rd are the fastest

Setup

var a = 5.678948;

Test runner

Ready to run.

Testing in
TestOps/sec
1
Math.round(a * 100) / 100
ready
2
Number(a.toFixed(2))
ready
3
Math.round((a + Number.EPSILON) * 100) / 100
ready
4
+(Math.round(a + "e+2") + "e-2")
ready

Revisions

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