I think this question is entry level. I used the following code to initialize a CGridView
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array('fromcompanyname:text:From','totaldue:number:Amount Due'),
));
The result of this code
'totaldue:number:Amount Due'
is that 45.04 becomes 45.
If I want to keep 2 digits behind 0, how should I do it?
The CFormatter document seems irrelevant to this issue, or I couldn’t figure it out by reading all the CGridView document.
Thanks!
Nicolas Xu
re1nald0
(Reinld17)
2
How about this?
'totaldue:number:number_format($data->Amount, 2)'
Keith
(Kburton)
4
'columns'=>array(
'fromcompanyname:text:From',
array(
'header'=>'Amount Due',
'value'=>function($data){
return number_format($data->totaldue, 2);
},
),
),
This totally helped me!!
Thanks:3 Good vibes.
Thank you! This totally helped! Though for future reference - what does function($data) do exactly?
Keith
(Kburton)
7
It’s an anonymous function that runs once for each row. $data is the model record for the current row.