Home > Article > Web Front-end > A simple way to get two or n digits after the decimal point of a number in JS
In js, sometimes it is necessary to get the two decimal places of a float number.
var num=10/3; function f(num,n){ return parseInt(num*Math.pow(10,n)+0.5,10)/Math.pow(10,n); } alert(f(num,2));