FeelRightz
FeelRightz

Reputation: 2979

Round a number down in JavaScript

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?

Upvotes: 0

Views: 83

Answers (3)

rdubya
rdubya

Reputation: 2916

You are looking for Math.floor() docs here

Upvotes: 3

user2575725
user2575725

Reputation:

Try round off:

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

OR

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

Upvotes: 5

DripDrop
DripDrop

Reputation: 1002

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

Upvotes: 1

Related Questions