php method to determine whether there is a decimal point: 1. Use the "strpos(numeric string,'.')" syntax. If the position where the decimal point first appears in the string is returned, there is a decimal point; 2 , use the "strrpos(numeric string,'.')" statement, if the position of the last occurrence of the decimal point in the string is returned, then there is.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php to determine whether there is Decimal point method
Method 1: Use the strpos() function
Use the strpos() function to get the first occurrence of the decimal point in the string The position, syntax:
strpos(数字字符串,'.')
If the position is returned, it is present, if FALSE is returned, there is no.
Example:
<?php header('content-type:text/html;charset=utf-8'); $nubs = 34123.456; if (strpos($nubs, '.') !== false) { echo '是小数,有小数点'; } else { echo '不是小数,没有小数点'; } ?>
Method 2: Use strrpos() function
Use strrpos( ) function gets the position of the last occurrence of the decimal point in the string, syntax:
strrpos(数字字符串,'.')
If the position is returned, it is present, if it returns FALSE, it is not.
<?php header('content-type:text/html;charset=utf-8'); $nubs = 34123; if (strrpos($nubs, '.') !== false) { echo '是小数,有小数点'; } else { echo '不是小数,没有小数点'; } ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine whether there is a decimal point in php. For more information, please follow other related articles on the PHP Chinese website!