PHP 数字格式 2 位小数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7350477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:32:34  来源:igfitidea点击:

PHP number format 2 decimal places

php

提问by James Maiden

Possible Duplicate:
PHP number format

可能重复:
PHP 数字格式

The following code out puts a figure for shipping cost based on a currency conversion that happens elsehwere, but it outputs with many decimal places. Can I alter something here that will produce a number with just 2 decimal places?

下面的代码输出了一个基于其他地方发生的货币转换的运费数字,但它输出了许多小数位。我可以在这里更改一些会产生只有 2 个小数位的数字吗?

if(isset($_POST['ShippingMethod'])){
            $order['data']  .= "\r\n ========== Shipping Cost ========== \r\n\r";
            $order['data'] .="\r\n Shipping Method Cost: ". $_SESSION['currency_symbol'].$_POST['ShippingMethod']. " \r\n";
            $form['price']['shipping'] +=$_POST['ShippingMethod'];
    }   

回答by Jan Dragsbaek