How to use indexOf () to detect decimals in JavaScript
This article will explain in detail how to use indexOf () to detect decimals in JavaScript. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
With indexOf (), the syntax "String (num) .indexOf (". ")" is a decimal if the return value is greater than "- 1".
Function isDot (num) {if (String (num) .indexOf (".") >-1) {console.log ("is a decimal");} else {console.log ("not a decimal");}} isDot (121.121); / / contains a decimal point isDot (454654) / / without decimal point, this is the end of the article on "how to use indexOf () to detect decimals in JavaScript". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.