2

I have a float numbers like : 0.24405750549007688

I would like to convert it to -> 0.2441

How can i do it with jquery ?

Levent Tulun
  • 701
  • 3
  • 9
  • 22

4 Answers4

1

Try using bellow

(6.688689).toFixed(); // equal to 7
(6.688689).toFixed(1); // equal to 6.7
(6.688689).toFixed(2); // equal to 6.69
Sujithrao
  • 789
  • 3
  • 12
  • 27
1
0.24405750549007688.toFixed(4)
"0.2441" <-- string

parseFloat(0.24405750549007688.toFixed(4))
0.2441 <-- number
BenG
  • 14,826
  • 5
  • 45
  • 60
0

var myFourDigit = (0.24405750549007688).toFixed(4) // will output 0.2440

Gumma Mocciaro
  • 1,205
  • 10
  • 24
0

not efficient but it will do the trick:

var n=0.24405750549007688
n*=10000;
n=Math.round(n)/10000;
console.log(n);
C.Vergnaud
  • 857
  • 6
  • 15