Double? Integer? — PHP

后端 未结 2 1126
滥情空心
滥情空心 2021-01-29 11:50

The following code generates two random decimal values, then subtracts them to get $c.

$a = mt_rand(5, 75);
$b = mt_rand(5, 75);
$adjuster = mt_rand         


        
相关标签:
2条回答
  • 2021-01-29 12:41

    Do something like this to see if $c is a whole number (possibly stored as a double):

    if(intval($c) == $c) {
        echo "I'm a whole number";
    }
    

    See here: http://3v4l.org/ubPK4

    0 讨论(0)
  • 2021-01-29 12:41

    A double subtracting a double results in a double, even if that number is a whole number

    $c = (int) ($b - $a);
    
    0 讨论(0)
提交回复
热议问题