How javascript converts floating-point numbers to integers
This article focuses on "how javascript converts floating-point numbers to integers". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how javascript converts floating-point numbers to integers.
Conversion methods: 1, the use of parseInt () function, syntax "parseInt (floating point)"; 2, the use of bit operator "|", syntax "0 | floating point"; 3, the use of bit operator "^", syntax "0 ^ floating point"; 4, the use of bit operator "~", syntax "~ floating point".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Javascript's method of converting floating-point numbers to integers
Method 1: use the parseInt () function
ParseInt (13.5) parseInt (22.5)
Method 2: use 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)
At this point, I believe you have a deeper understanding of "how javascript converts floating-point numbers into integers". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!