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
  • 265,109
  • 74
  • 539
  • 565
FeelRightz
  • 2,777
  • 2
  • 38
  • 73

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,916
  • 1
  • 16
  • 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
  • 994
  • 1
  • 9
  • 18