How to round float numbers in javascript?

2022-08-29 23:32:18

I need to round for example to , but it always shows me .6.6886896.77

My method:

Math.round(6.688689);
//or
Math.round(6.688689, 1);
//or 
Math.round(6.688689, 2);

But result always is the same ... What am I doing wrong?7


答案 1
Number((6.688689).toFixed(1)); // 6.7

答案 2
var number = 6.688689;
var roundedNumber = Math.round(number * 10) / 10;