JavaScript only has a Number type that stores floating point values.

There is no int.

Edit:

If you want to format the number as a string with two digits after the decimal point use:

(4).toFixed(2)
Answer from Alex Jasmin on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-a-float-number-to-the-whole-number-in-javascript
How to Convert a Float Number to the Whole Number in JavaScript? - GeeksforGeeks
July 11, 2025 - // float value is 4.59; let x = 4.59; let z = Math.floor(x); console.log("Converted value of " + x + " is " + z); ... Return the smallest integer greater than or equal to a given number.
Discussions

Hey JavaScript, can you turn my float into int properly?
For those who haven’t seen this, it’s because parseInt() takes a string argument. 0.0000005 automatically typecasts to the string ‘5e-7’ in scientific notation. parseInt sees the 5, uses it, sees the e which is not a decimal number, and stops. If you do parseInt(0.0000005, 16) to parse the string in base 16, the answer becomes 94 instead of 5 because e is also a hex digit. More on reddit.com
🌐 r/ProgrammerAnimemes
86
1701
February 3, 2022
How do I convert an integer to a float in JavaScript? - Stack Overflow
I've got an integer (e.g. 12), and I want to convert it to a floating point number, with a specified number of decimal places. ... function intToFloat(num, decimal) { [code goes here] } intToFloat(12, 1) // returns 12.0 intToFloat(12, 2) // returns 12.00 // and so on… ... Save this answer. ... Show activity on this post. What you have is already a floating point number, they're all 64-bit floating point numbers in JavaScript... More on stackoverflow.com
🌐 stackoverflow.com
Does JavaScript supports conversion of integer X to X.0 as typeof number?
This doesn't really make sense in context of JavaScript. As far as JS is concerned, the numbers 5 and 5.0 are exactly the same. In context of JSON, the numbers are also exactly the same. Hence, you can't really "make 5 into 5.0" because it already is, and the fact the decimals are not displayed is just how the number happens to be formatted by the particular JS engine that's displaying it to you. If you have a bizarre API which refuses to accept numbers such as 5, but won't accept a string '5.0', you will probably have to format the values yourself. Eg. use whatever.toFixed(1), which gives you a string, and then manually strip out the string delimiters from the JSON data. You might be able to do this using the optional replacer function for JSON.stringify - just have it check if the value is typeof 'number', and ensure it always uses toFixed when formatting them. More on reddit.com
🌐 r/learnjavascript
41
21
January 1, 2023
performance - Fastest way to cast a float to an int in javascript? - Stack Overflow
The issue with bitwise operators ... to 32bit integers in the process, if that is fine for your use-case then go ahead. See MDN docs on bitwise OR, bitwise NOT, bitwise AND and bitwise XOR or their respective ECMAScript documentation. The parseInt function is usually way slower than the alternatives, most likely because it expects a string as parameter. The solution with the modulo operator should be used with caution as it may bite you in the ass sometime due to floating point issues ... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 16
2263
var intvalue = Math.floor( floatvalue );
var intvalue = Math.ceil( floatvalue ); 
var intvalue = Math.round( floatvalue );

// `Math.trunc` was added in ECMAScript 6
var intvalue = Math.trunc( floatvalue );

Math object reference


Examples

Positive
// value=x        //  x=5          5<x<5.5      5.5<=x<6  

Math.floor(value) //  5            5            5
Math.ceil(value)  //  5            6            6
Math.round(value) //  5            5            6
Math.trunc(value) //  5            5            5
parseInt(value)   //  5            5            5
~~value           //  5            5            5
value | 0         //  5            5            5
value >> 0        //  5            5            5
value >>> 0       //  5            5            5
value - value % 1 //  5            5            5
Negative
// value=x        // x=-5         -5>x>=-5.5   -5.5>x>-6

Math.floor(value) // -5           -6           -6
Math.ceil(value)  // -5           -5           -5
Math.round(value) // -5           -5           -6
Math.trunc(value) // -5           -5           -5
parseInt(value)   // -5           -5           -5
value | 0         // -5           -5           -5
~~value           // -5           -5           -5
value >> 0        // -5           -5           -5
value >>> 0       // 4294967291   4294967291   4294967291
value - value % 1 // -5           -5           -5
Positive - Larger numbers
// x = Number.MAX_SAFE_INTEGER/10 // =900719925474099.1

// value=x            x=900719925474099    x=900719925474099.4  x=900719925474099.5
           
Math.floor(value) //  900719925474099      900719925474099      900719925474099
Math.ceil(value)  //  900719925474099      900719925474100      900719925474100
Math.round(value) //  900719925474099      900719925474099      900719925474100
Math.trunc(value) //  900719925474099      900719925474099      900719925474099
parseInt(value)   //  900719925474099      900719925474099      900719925474099
value | 0         //  858993459            858993459            858993459
~~value           //  858993459            858993459            858993459
value >> 0        //  858993459            858993459            858993459
value >>> 0       //  858993459            858993459            858993459
value - value % 1 //  900719925474099      900719925474099      900719925474099
Negative - Larger numbers
// x = Number.MAX_SAFE_INTEGER/10 * -1 // -900719925474099.1

// value = x      // x=-900719925474099   x=-900719925474099.5 x=-900719925474099.6

Math.floor(value) // -900719925474099     -900719925474100     -900719925474100
Math.ceil(value)  // -900719925474099     -900719925474099     -900719925474099
Math.round(value) // -900719925474099     -900719925474099     -900719925474100
Math.trunc(value) // -900719925474099     -900719925474099     -900719925474099
parseInt(value)   // -900719925474099     -900719925474099     -900719925474099
value | 0         // -858993459           -858993459           -858993459
~~value           // -858993459           -858993459           -858993459
value >> 0        // -858993459           -858993459           -858993459
value >>> 0       //  3435973837           3435973837           3435973837
value - value % 1 // -900719925474099     -900719925474099     -900719925474099
2 of 16
348

Bitwise OR operator

A bitwise or operator can be used to truncate floating point figures and it works for positives as well as negatives:

function float2int (value) {
    return value | 0;
}

Results

float2int(3.1) == 3
float2int(-3.1) == -3
float2int(3.9) == 3
float2int(-3.9) == -3

Performance comparison?

I've created a JSPerf test that compares performance between:

  • Math.floor(val)
  • val | 0 bitwise OR
  • ~~val bitwise NOT
  • parseInt(val)

that only works with positive numbers. In this case you're safe to use bitwise operations well as Math.floor function.

But if you need your code to work with positives as well as negatives, then a bitwise operation is the fastest (OR being the preferred one). This other JSPerf test compares the same where it's pretty obvious that because of the additional sign checking Math is now the slowest of the four.

Note

As stated in comments, BITWISE operators operate on signed 32bit integers, therefore large numbers will be converted, example:

1234567890  | 0 => 1234567890
12345678901 | 0 => -539222987
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript float to int
How to Convert a Float Number to Int in JavaScript | Delft Stack
February 2, 2024 - The bitwise operators operate on the signed 32-bit numbers ignoring the decimal value. Hence, we get the integer number part of the float value. We can use the JavaScript Math library, which has various functions to get integers from floating-point numbers. Unlike the bitwise operators, these offer additional features based on requirements like rounding off values to the nearest numbers, truncating values, etc.
🌐
Code Highlights
code-hl.com › home › javascript › tutorials
5 Easy Ways to Convert JavaScript Float to Int | Code Highlights
June 4, 2024 - The bitwise OR operator can also convert a float to an integer by truncating the decimal part. ... All these methods are compatible with major web browsers, including Chrome, Firefox, Safari, Edge, and Internet Explorer. This ensures that your code will run smoothly across different environments. In this tutorial, we explored five simple methods to convert a JavaScript float to an int:
🌐
IQCode
iqcode.com › code › javascript › convert-int-to-float-in-javascript
convert int to float in javascript Code Example - IQCode.com
October 25, 2021 - var int = 10; var float = parseFloat(int).toFixed(2); console.log(float); // 10.00 var threedots = 8; var float2 = parseFloat(threedots).toF...
🌐
Reddit
reddit.com › r/programmeranimemes › hey javascript, can you turn my float into int properly?
[Mature Content] r/ProgrammerAnimemes on Reddit: Hey JavaScript, can you turn my float into int properly?
February 3, 2022 - Javascript dont has int or float type, all they has is number type and bignumber, so if you want to remove decimal point in your number, use the floor function
Find elsewhere
🌐
Just Academy
justacademy.co › blog-detail › how-to-convert-float-to-int-in-javascript
How To Convert Float To Int In JavaScript by Roshan Chaturvedi | JustAcademy
6) Type Conversion: You can simply convert a float to an integer by assigning it to a variable of type int. JavaScript will automatically truncate the decimal value.
🌐
Rip Tutorial
riptutorial.com › float to integer
JavaScript Tutorial => Float to Integer
To convert a float to an integer, JavaScript provides multiple methods.
🌐
Itsourcecode
itsourcecode.com › home › converting floats to integers in javascript: 10 effective ways
Converting Floats to Integers in JavaScript: 10 Effective Ways
July 9, 2026 - For example, 4.14 and 0.75 are floating-point numbers · Integers are whole numbers without any fractional parts. They are also represented using the number data type in JavaScript. Examples of integers include 8, 10, and -16. JavaScript offers several methods to convert float to int, each with its own advantages and use cases.
🌐
TutorialsPoint
tutorialspoint.com › article › how-do-i-convert-a-float-number-to-a-whole-number-in-javascript
How do I convert a float number to a whole number in JavaScript?
March 15, 2026 - When we perform the Bitwise OR (|) operation of 0 with the float number, it removes the decimal part from the current number and converts it to the whole number.
🌐
Reddit
reddit.com › r/learnjavascript › does javascript supports conversion of integer x to x.0 as typeof number?
r/learnjavascript on Reddit: Does JavaScript supports conversion of integer X to X.0 as typeof number?
January 1, 2023 -

Given string lets say “5” I want to convert it to 5.0 (typeof Number)

Already tried combinations/permutations of all the following: parseFloat() toFixed() toPrecision() Number() Also tried with “+” (implicit Number casting)

I always end up with either typeof string Or just the number 5

Its for an API that expects “float” but does not accept integers (5 is invalid, 5.0 is valid)

Any ideas would be appreciated.

🌐
Codemia
codemia.io › home › knowledge hub › how do i convert a float number to a whole number in javascript?
How do I convert a float number to a whole number in JavaScript? | Codemia
December 28, 2024 - For more advanced use cases, JavaScript offers bitwise operators such as the bitwise OR (|), which can truncate floating-point numbers. This method is generally faster but should be used with caution, as it only works correctly within the 32-bit integer range. ... The parseInt() function parses a string and returns an integer. It is also used to convert floats to integers by simply ignoring the decimal part without any rounding.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-convert-a-float-number-to-a-whole-number-in-javascript.php
How to Convert a Float Number to a Whole Number in JavaScript
You can use the trunc() method to get the integer part of a number by removing any fractional digits. This method was added in ECMAScript 6 and supported by the latest browsers such as Chrome, Firefox, Safari, Opera, and Edge browsers.
🌐
W3Schools
w3schools.com › jsref › jsref_parsefloat.asp
JavaScript parseFloat() Method
The parseFloat() method parses a value as a string and returns the first number.