Rounding Function for JavaScript

Maybe some of you already know this, but the obvious method of rounding in JavaScript can lead to errors. Here’s a great function I found:

REF: Rounding Decimals in JavaScript

###Script:

function round(value, decimals) {
  return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
}

round(1.005, 2); // 1.01
1 Like