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
  • 651
  • 3
  • 9
  • 20

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
  • 791
  • 3
  • 12
  • 27
1
0.24405750549007688.toFixed(4)
"0.2441" <-- string

parseFloat(0.24405750549007688.toFixed(4))
0.2441 <-- number
BenG
  • 14,280
  • 5
  • 44
  • 59
0

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

Gumma Mocciaro
  • 1,165
  • 8
  • 23
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
  • 807
  • 5
  • 15