Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
toFixed vs mathjs round
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
toFixed
15348779.0 Ops/sec
mathjs.round
1021792.2 Ops/sec
round2
55342768.0 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjs/10.0.0/math.min.js'></script>
Script Preparation code:
var num = -6.864601706668172e-10 function round2(num, decimalPlaces = 0) { // return Math.round(value * (10 ** decimals)) / (10 ** decimals); // return Number(value.toFixed(decimals)); if (num < 0) { return -round2(-num, decimalPlaces); } var p = Math.pow(10, decimalPlaces); var n = num * p; var f = n - Math.floor(n); var e = Number.EPSILON * n; // Determine whether this fraction is a midpoint value. return (f >= .5 - e) ? Math.ceil(n) / p : Math.floor(n) / p; }
Tests:
toFixed
parseFloat(num.toFixed(8))
mathjs.round
math.round(num, 8)
round2
round2(num, 8)