How to do integer division in javascript (Getting division answer in int not float)?

Nakib picture Nakib · Sep 21, 2013 · Viewed 160.7k times · Source

Is there any function in Javascript that lets you do integer division, I mean getting division answer in int, not in floating point number.

var x = 455/10;
// Now x is 45.5
// Expected x to be 45

But I want x to be 45. I am trying to eliminate last digit from the number.

Answer

Neeraj picture Neeraj · Sep 21, 2013
var answer = Math.floor(x)

I sincerely hope this will help future searchers when googling for this common question.