checking if a number is float in PHP

后端 未结 4 1294
挽巷
挽巷 2020-11-30 14:30

This is really weird. I have this piece of code.

$rewardAmt = $amt;
if(is_float($rewardAmt)){
      print_r(\"is float\");die;
} else {
      print_r(\"is no         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 14:58

    You can check this by

    $float = floatval($num); //Convert the string to a float
    if($float && intval($float) != $float) // Check if the converted int is same as the float value...
    {
        // $num is a float
    }else{
        // $num is an integer
    }
    

提交回复
热议问题