How to round float numbers in javascript?

Vitalii Ponomar picture Vitalii Ponomar · Feb 26, 2012 · Viewed 363.3k times · Source

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?

Answer

davin picture davin · Feb 26, 2012
Number((6.688689).toFixed(1)); // 6.7