Rounding can usethe toFixed() method, the toFixed() method can round a Number to a number with a specified number of decimal places.

The code is as follows:

toFixed() Method

var num =2.446242342; num = num.toFixed(2); //The output result is 2.45

Try it Yourself »

In addition, likeround()、floor()、ceil()etc. cannot truly round, there are precision issues.

round() can ensure precision is correct in the following way:

round() Method

var num =2.446242342; num = Math.round((num + Number.EPSILON) * 100) / 100; //The output result is 2.45

Try it Yourself »

Reference Articles