Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use indexOf () to detect decimals in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 03:00:23 11月17日 Update

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.

Tags: Decimal articles testing decimal point more good practical content articles knowledge grammar reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS Apple Linux MySQL