Skip to content

Round to at most 2 decimal places in JavaScript


var num = "987.654321";

var numb = 987.654321;
numb = numb.toFixed(2);


function roundToTwo(num) {    
    return +(Math.round(num + "e+2")  + "e-2");
See also  Design HashMap - Leetcode Challenge - Python Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.