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:
Contact Us