Search code examples
javascriptrounding

How to round float numbers in javascript?


I need to round for example 6.688689 to 6.7, but it always shows me 7.

My method:

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

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


Solution

  • Number((6.688689).toFixed(1)); // 6.7