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

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.

This question is related to javascript division integer-division

The answer is


var answer = Math.floor(x)

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


var x = parseInt(455/10);

The parseInt() function parses a string and returns an integer.

The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.

If the radix parameter is omitted, JavaScript assumes the following:

If the string begins with "0x", the radix is 16 (hexadecimal)
If the string begins with "0", the radix is 8 (octal). This feature is deprecated
If the string begins with any other value, the radix is 10 (decimal)

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to division

Division in Python 2.7. and 3.3 Python3 integer division How to do integer division in javascript (Getting division answer in int not float)? How can I do division with variables in a Linux shell? Python: Remove division decimal How to get a float result by dividing two integer values using T-SQL? Divide a number by 3 without using *, /, +, -, % operators Why does integer division in C# return an integer and not a float? How to check if number is divisible by a certain number? C++ Best way to get integer division and remainder

Examples related to integer-division

How to do integer division in javascript (Getting division answer in int not float)? Dividing two integers to produce a float result Assembly Language - How to do Modulo? Why does dividing two int not yield the right value when assigned to double? Find the division remainder of a number Why is division in Ruby returning an integer instead of decimal value? Int division: Why is the result of 1/3 == 0? Integer division with remainder in JavaScript? What is the behavior of integer division? Integer division: How do you produce a double?