Check whether a float number contains decimals or not

前端 未结 7 2355
难免孤独
难免孤独 2020-12-29 07:02

How can I check whether a float number contains decimals like 2.10, 2.45, 12382.66 and not 2.00 , 12382.00. I want to know if the number is \"round\" or not. How can I do th

相关标签:
7条回答
  • 2020-12-29 08:01

    PHP solution:

    function hasDecimals($x)
    {
        return floatval($x) - intval($x) != 0;
    }
    
    0 讨论(0)
提交回复
热议问题