Number format in CGridView

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

How about this?


'totaldue:number:number_format($data->Amount, 2)'

it doesn’t work for me




'columns'=>array(

    'fromcompanyname:text:From',

    array(

        'header'=>'Amount Due',

        'value'=>function($data){

            return number_format($data->totaldue, 2);

        },

    ),

),



This totally helped me!! :lol: Thanks:3 Good vibes.

Thank you! This totally helped! Though for future reference - what does function($data) do exactly?

It’s an anonymous function that runs once for each row. $data is the model record for the current row.