parseInt (floating argument)

Accept the string and convert it into an integer. 

Syntax:

parseInt(Value, radix);

Example: Here is basic example of above method.

javascript




// float value is 3.54;
let x = 3.54;
let z = parseInt(x);
console.log("Converted value of " + x + " is " + z);


Output:

Converted value of 3.54 is 3

How to convert a float number to the whole number in JavaScript ?

In this article, we will convert a float number to a whole number in JavaScript.

Below are various methods to convert float numbers to whole numbers in JavaScript:

Table of Content

  • Math.floor (floating argument):
  • Math.ceil (floating argument)
  • Math.round (floating argument)
  • Math.trunc (floating argument)
  • parseInt (floating argument)
  • double bitwise not (~~) operator
  • JavaScript bitwise OR (|) Operator
  • Using shift (>>) operator
  • Using unsigned shift (>>>) operator
  • By subtracting the fractional part
  • Using XOR (^) operator Syntax:

Similar Reads

Math.floor (floating argument)

Round off the number passed as a parameter to its nearest integer in the Downward direction....

Math.ceil (floating argument)

...

Math.round (floating argument)

Return the smallest integer greater than or equal to a given number....

Math.trunc (floating argument)

...

parseInt (floating argument)

Round a number to its nearest integer....

double bitwise not (~~) operator

...

JavaScript bitwise OR (|) Operator

Return the integer part of a floating-point number by removing the fractional digits....

Using shift (>>) operator

...

Using unsigned shift (>>>) operator

Accept the string and convert it into an integer....

By subtracting the fractional part

...

Using XOR (^) operator

Round a number to zero. If an operand is a number and it’s not NaN or Infinity....