Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php judge whether a number can be a decimal or not?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "php how to judge whether a number can be a decimal", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "php how to judge whether a number can be a decimal" this article.

In PHP, you can use the strpos () function to determine whether a number is a decimal point, the function can find the decimal point in the number, return flase that the number does not have a decimal point, the number is not a decimal point, on the contrary, it means that the number has a decimal point, the number is a decimal point, the syntax is "if (number string,'.')! = false)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Php's method of judging that a number cannot be a decimal

1. In PHP, you can use the strpos () function to find the first occurrence of a string in another string. The syntax of the strpos () function is:

Strpos (string,find,start)

Among them, it should be noted that:

The parameter strings is required to indicate the string to be searched, the find parameter is also required to specify the string to find, and the start parameter is optional to specify where to start the search.

The result returned is the first occurrence of the string in another string, or FALSE if the string is not found.

To determine whether it is a decimal, we can use the strpos function to find out whether the decimal point appears in the number string, as follows:

Strpos (numeric string,'.')

If it is a decimal, the result returned is the position where the decimal point first appeared. If it is not a decimal point, there is no decimal point, and the result returned is false.

2. You can determine whether the result returned by the strpos function in the previous step is equal to flase. If it is true, it is a decimal. If it is false, it is not a decimal.

The code is as follows:

Output result:

Example:

Output result:

The above is all the contents of the article "how to judge whether a number can be a decimal or not by php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report