Round to at most 2 decimal places in JavaScript
toFixed()
var num = "987.654321"; parseFloat(num).toFixed(2); var numb = 987.654321; numb = numb.toFixed(2);
Math.round()
function roundToTwo(num) { return +(Math.round(num + "e+2") + "e-2"); }
var num = "987.654321"; parseFloat(num).toFixed(2); var numb = 987.654321; numb = numb.toFixed(2);
function roundToTwo(num) { return +(Math.round(num + "e+2") + "e-2"); }