[英]Remove useless zero after number using php code
我们正在使用以下代码在磁网站上显示运费:
<?php echo "Selling Price + " . $_excl . " Delivery "; ?>
$_excl
将返回值。
其显示结果为10.00、20.00 ...等。
我想从“ 10.00”中删除.00 ,并仅显示10。
我尝试了以下代码:
echo "Selling Price + " . round($_excl,0) . " Delivery ";
echo "Selling Price + " . round($_excl) . " Delivery ";
echo "Selling Price + " . $_excl + 0 . " Delivery ";
没有任何帮助,请给我更新的代码
您可以使用(int)
, number_format()
或round()
或intval()
$num = '10.00';
echo (int)$num ."\n"; //print 10
echo number_format($num,0) ."\n"; //print 10
echo round($num,0) ."\n"; // print 10
echo intval($num) ."\n"; // print 10
所以你的情况
echo "Selling Price + " . (int)$_excl . " Delivery " . "\n";
echo "Selling Price + " . number_format($_excl,0) . " Delivery " . "\n";
echo "Selling Price + " . round($_excl,0) . " Delivery " . "\n";
echo "Selling Price + " . intval($_excl) . " Delivery " . "\n";
您可以使用number_format() :
echo "Selling Price + " . number_format($_excl, 0) . " Delivery ";
$num + 0
可以解决问题。
echo 125.00 + 0; // 125
echo '125.00' + 0; // 125
echo 966.70 + 0; // 966.7
在内部,这等效于使用(float)$num
或floatval($num)
强制转换为float,但是我发现它更简单。
更新资料
echo "Selling Price + " . ($_excl + 0) . " Delivery ";
尝试
echo "Selling Price + " . (int)$_excl . " Delivery ";
例如
$f = "10.00";
echo (int)$f; //gives 10
希望它帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.