PHP - How Compare Decimal Values
I'm trying figure out how to compare decimal values in PHP properly.
$get_decimal_value = mysqli_query($conn, "SELECT DecimalValue FROM my_table WHERE Id = $some_id LIMIT 1")
or die($db_conn_err);
if(mysqli_num_rows($get_decimal_value) == 1 )
{
$row = mysqli_开发者_开发百科fetch_array($get_decimal_value);
$my_decimal = $row['DecimalValue'];
if($my_decimal > 0)
{
// IS THIS CORRECT???
// Does it need to be like '0.00' ?
// it seems to work both ways...
}
}
Thank you!
PHP is weakly typed, so e.g. 1.0 > 0
should hold no surprises (even things like 1 + "2"
work as expected).
It is correct. PHP can transform 0 to float without any problems.
精彩评论