Yii 数字格式 [英] Yii Number Formatting
本文介绍了Yii 数字格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试格式化我的 cgridview 列以显示带有 2 个小数位的数字.
Im trying to format my cgridview column to display numbers with 2 decimal places.
示例 9137 应显示为 91.37 而不是 9137.00
Example 9137 should display as 91.37 not 9137.00
有没有简单的方法可以用 PHP 或 Yii 做到这一点?
Is there a simple way to do this with PHP or Yii?
推荐答案
只需将特定列设置为两个属性的关联数组:name
作为其名称和 value
作为用于获得结果的表达式.然后相应地修改此表达式:数字应除以 100,然后进行格式化.例如:
Just set the specific column as an associative array of two properties: name
as its name and value
as the expression that is applied to get the result. Then modify this expression accordingly: the number should be divided by 100, then formatted. For example:
$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)',
),
),
));
这篇关于Yii 数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文