Check if number is decimal

前端 未结 17 1804
生来不讨喜
生来不讨喜 2020-12-09 14:53

I need to check in PHP if user entered a decimal number (US way, with decimal point: X.XXX)

Any reliable way to do this?

17条回答
  •  醉酒成梦
    2020-12-09 15:01

    A total cludge.. but hey it works !

    $numpart = explode(".", $sumnum); 
    
    if ((exists($numpart[1]) && ($numpart[1] > 0 )){
    //    it's a decimal that is greater than zero
    } else {
    // its not a decimal, or the decimal is zero
    }
    

提交回复
热议问题