Home > Article > Web Front-end > JS retains two decimal places and multiple decimal places sample code_javascript skills
// Float data is rounded to 2 decimal places;
function to2bits(flt) {
if(parseFloat(flt) == flt)
return Math.round(flt * 100) / 100;
// to 4 decimal places, return Math.round(flt * 10000) / 10000;
else
return 0;
}