Rounding

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
numeric
const precision = 2
const value = 1.005
const multiplier = Math.pow(10.0, precision);
 
const integerPart = Math.trunc(value);
let fractionPart = value - integerPart;

const correctionMultiplier = Math.pow(10.0, 8 + 1);
fractionPart = Math.round(fractionPart * correctionMultiplier) / correctionMultiplier;

const roundedFraction = Math.round(fractionPart * multiplier)/multiplier

console.log(integerPart + roundedFraction)
ready
exp
const precision = 2
const value = 1.005
const roundedValue = Number(Math.round(value +'e'+precision)+'e-'+precision)


console.log(roundedValue)
ready

Revisions

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