Floating-point error mitigation (v2)

Revision 2 of this benchmark created on


Setup

round1 = value => {
  const factor = 1e10;
  return Math.round(value*factor)/factor;
}

round2 = value => {
  return Number(value.toPrecision(10));
}

round3 = value => {
  return Number(value.toFixed(10));
}

round4 = value => {
  return parseFloat(value.toPrecision(10));
}

Test runner

Ready to run.

Testing in
TestOps/sec
Math.round
round1(0.1+0.2);
ready
Number(toPrecision)
round2(0.1+0.2);
ready
Number(toFixed)
round3(0.1+0.2);
ready
parseFloat(toPrecision)
round4(0.1+0.2);
ready

Revisions

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