Php Yii数字格式

Php Yii数字格式,php,yii,Php,Yii,我正在尝试格式化我的cgridview列,以显示小数点后2位的数字 示例9137应显示为91.37,而不是9137.00 使用PHP或Yii有一种简单的方法吗?只需将特定列设置为两个属性的关联数组:name作为其名称,value作为用于获取结果的表达式。然后相应地修改这个表达式:数字应该除以100,然后格式化。例如: $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider' => $dataProvid

我正在尝试格式化我的cgridview列,以显示小数点后2位的数字

示例9137应显示为91.37,而不是9137.00


使用PHP或Yii有一种简单的方法吗?

只需将特定列设置为两个属性的关联数组:
name
作为其名称,
value
作为用于获取结果的表达式。然后相应地修改这个表达式:数字应该除以100,然后格式化。例如:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $dataProvider,
    'columns'      => array(
        'cost',          // display the 'cost' attribute
        array(           // display the 'cost_in_dollars' using an expression
            'name'  =>  'cost_in_dollars',
            'value' =>  'number_format($data->cost/100, 2)',
        ),
    ),
));

在显示数据之前,是否将数据除以100?