Home > Article > Web Front-end > How to convert floating point number to integer in javascript
Conversion method: 1. Use the parseInt() function, the syntax "parseInt (floating point number)"; 2. Use the bit operator "|", the syntax "0 | floating point number"; 3. Use the bit operator "^", the syntax is "0 ^ floating point number"; 4. Use the bit operator "~~", the syntax is "~~floating point number".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript method of converting floating point numbers to integers
Method 1: Use parseInt() function
parseInt(13.5); parseInt(22.5);
Method 2: Using the bit operator "|"
console.log(0 | 123.45)
Method 3 : Use the bit operator "^"
console.log(0 ^ 123.45)
Method 4: Use the bit operator "~~"
console.log(~~ 123.45); console.log(~~ 123.4545);
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to convert floating point number to integer in javascript. For more information, please follow other related articles on the PHP Chinese website!