php verifies whether it is two decimal places
1. First create a function fun and receive a parameter num;
2. Then use preg_match within the function to perform regular matching on num;
3. If the final match is successful, num will be two decimal places.
The code is as follows:
<?php function fun($num) { if (preg_match('/^[0-9]+(.[0-9]{2})$/', $num)) { echo $num, '对<br>'; }else{ echo $num, '错<br>'; } } fun(111); fun(1112.01); fun(2324.1); fun(2324.15); fun(2324.157); fun(0.57);
Result:
111错 1112.01对 2324.1错 2324.15对 2324.157错 0.57对
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of php verify whether it is two decimal places. For more information, please follow other related articles on the PHP Chinese website!