toCents vs roundToCents

Benchmark created on


Setup

function roundToCents(value, places = 2) { if (places < 0) places = 2; const factor = Math.pow(10, places); return Math.round(value * factor); }


function toCents(val) { const n = Number(String(val).replace(',', '.')); if (!Number.isFinite(n)) return 0; return Math.round(n * 100); }

Test runner

Ready to run.

Testing in
TestOps/sec
roundToCents
roundToCents(1000)
ready
toCents
toCents(1000)
ready

Revisions

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