Php条件语句:如果数据库字段等于“;0.0“;必须隐藏到页面
在我的数据库中,我将一些字段设置为Php条件语句:如果数据库字段等于“;0.0“;必须隐藏到页面,php,conditional-statements,Php,Conditional Statements,在我的数据库中,我将一些字段设置为decimal,这样我就可以输入带有小数点的数字 在我的数据库中,即使我没有在输入字段中输入任何内容,其值始终为0.0 在我的情况下,我不希望0.0显示在我的页面中,因此我尝试以下方法: <?php if(!empty($current_orders["order_item"])){ echo "<p>Credit Amount: <span class=\"colorRed\">Php ". $cur
decimal
,这样我就可以输入带有小数点的数字
在我的数据库中,即使我没有在输入字段中输入任何内容,其值始终为0.0
在我的情况下,我不希望0.0
显示在我的页面中,因此我尝试以下方法:
<?php
if(!empty($current_orders["order_item"])){
echo "<p>Credit Amount: <span class=\"colorRed\">Php ". $current_orders["order_item"]."</span></p>";
} else {
echo null;
}
?>
它不起作用了 非空表示这些变量有值。空表示这些变量为空。0.0是一个值。因此,将代码更改为:
<?php if($current_orders["order_item"] > 0.0){
echo "<p>Credit Amount: <span class=\"colorRed\">Php "
. $current_orders["order_item"] . "</span></p>";
} else {
echo null;
}
?>
非空表示这些变量有值。空表示这些变量为空。0.0是一个值。因此,将代码更改为:
<?php if($current_orders["order_item"] > 0.0){
echo "<p>Credit Amount: <span class=\"colorRed\">Php "
. $current_orders["order_item"] . "</span></p>";
} else {
echo null;
}
?>
您可以使用以下代码消除此问题
$amount = 0.0;
if((!empty($amount)) && $amount>0){
echo "<p>Credit Amount: <span class=\"colorRed\">Php ". $amount."</span></p>";
} else {
echo null;
}
$amount=0.0;
如果((!empty($amount))&&$amount>0){
echo“贷方金额:Php.“$Amount.””;
}否则{
回波零点;
}
如果要显示-ve值,只需将条件$amount>0更改为$amount=0,否则它将不显示th-ve值您可以使用以下代码消除此问题
$amount = 0.0;
if((!empty($amount)) && $amount>0){
echo "<p>Credit Amount: <span class=\"colorRed\">Php ". $amount."</span></p>";
} else {
echo null;
}
$amount=0.0;
如果((!empty($amount))&&$amount>0){
echo“贷方金额:Php.“$Amount.””;
}否则{
回波零点;
}
如果要显示-ve值,只需将条件$amount>0更改为$amount=0,否则它将不显示th-ve值您可以使用php中的函数来比较浮点值
如果两个操作数相等,则返回0;如果左操作数大于右操作数,则返回1;否则返回-1
<?php
if(bccomp($current_orders["order_item"],0.0,1) == 0){
echo "<p>Credit Amount: <span class=\"colorRed\">Php ". $current_orders["order_item"]."</span></p>";
} else {
echo null;
}
您可以使用php中的函数来比较浮点值
如果两个操作数相等,则返回0;如果左操作数大于右操作数,则返回1;否则返回-1
<?php
if(bccomp($current_orders["order_item"],0.0,1) == 0){
echo "<p>Credit Amount: <span class=\"colorRed\">Php ". $current_orders["order_item"]."</span></p>";
} else {
echo null;
}
是否也会显示可能的负值?示例i的值为-1.5
是否可以显示?@jhunlio,只需将>更改为==是否也可以显示可能的负值?示例i的值为-1.5
是否可以显示?@jhunlio,只需更改>即可==