0

I know this maybe very simple and common but I want to know about this calculation:

Example: I have a decimal number 4.716981132075472, but I only need the 4 number, is there any calculation able to do this?

Sampson
  • 259,174
  • 73
  • 529
  • 557
FeelRightz
  • 2,479
  • 2
  • 30
  • 60

3 Answers3

5

Try round off:

var result = 4.716981132075472 << 0;
alert(result);

OR

var result = Math.floor(4.716981132075472);
alert(result);
3

You are looking for Math.floor() docs here

rdubya
  • 2,906
  • 1
  • 14
  • 20
  • MDN is great, but the definitive documentation is here: [*ECMA-262 §15.8.2.9*](http://ecma-international.org/ecma-262/5.1/#sec-15.8.2.9). :-) – RobG Jan 09 '15 at 02:48
1

Try Math.floor( 4.716981132075472);. This rounds the number down to the nearest integer, thus solving your problem.

DripDrop
  • 986
  • 1
  • 8
  • 18