How to convert decimals to integers in js
Most people do not understand the knowledge points of this article "how to convert decimals to integers in js", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how decimals to integers in js" article.
1. Use the "parseInt" statement.
[xss_clean] (parseInt ("10") + "); [xss_clean] (parseInt (" 10.33 ") +"); [xss_clean] (parseInt ("34 45 66") + "); [xss_clean] (parseInt (" 60 ") +"); [xss_clean] (parseInt ("40 years") + "); [xss_clean] (parseInt (" He was 40 ") +"); [xss_clean] (") [xss_clean] (parseInt ("10", 10) + "); [xss_clean] (parseInt (" 010 ") +"); [xss_clean] (parseInt ("10", 8) + "); [xss_clean] (parseInt (" 0x10 ") +"); [xss_clean] (parseInt ("10", 16) + ")
2. Use the "~ ~ decimal value" statement.
Var decimal=4;var integer = ~ decimal; / / 4 = ~ ~ 4.123console.log (integer)
3. Use the "Math.floor" statement.
Console.log (Math.floor (2.5)); / / 2console.log (Math.floor (- 2.5)); / /-3
4. Use the "Math.ceil" statement.
Console.log (Math.ceil (2.5)); / / 3console.log (Math.ceil (- 2.5)); / /-2
5. Use the "Math.round" statement.
Console.log (Math.round (- 2.5)); / / 3console.log (Math.round (- 2.5)); / /-2console.log (Math.round (- 2.6)) / /-3 above is the content of this article on "how to convert decimals to integers in js". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.