1, the problem background
In general, the rate shown in the table, the rate of treatment is: to retain two decimal places, and keep up
2. Implementation example
<?xml version= "1.0" encoding= "Utf-8"?> <s:application xmlns:fx= "http://ns.adobe.com/mxml/2009" Library://ns.adobe.com/flex/spark "xmlns:mx=" library://ns.adobe.com/flex/mx "width=" 100% "height=" 100% "fontSize=" "fontfamily=" Microsoft Ya Hei "> <s:layout> <s:BasicLayout/> </s:layout> <fx:Script> <!
[cdata[import mx.collections.ArrayCollection;
Import mx.events.FlexEvent; [bindable]//Tabular data binding private var gridarray:arraycollection = new ArrayCollection ([{week: "Monday", Apple: "3676", Rate: "0.786 8 "}, {week:" Tuesday ", Apple:" 4534 ", Rate:" 0.65454 "}, {week:" Wednesday ", Apple:" 6758 ", Rate:" 0.876454 "}, {week:" Thursday ", Apple:" 9808 ", Rate:" 0.34224 "}, {week:" Friday ", Apple:" 6567 ", Rate:" 0.9876523 "}, {week:" Saturday ", Apple:" 9000 ", Rate:" 0.566777 "}, {week:"
Sunday ", Apple:" 4533 ", Rate:" 0.988787 "}]; /** * Format the ratio in the table/Private function Formatdatagrid (item:object,column:datagridcolumn): String {var temp:number = i
Tem.rate;
var data:string = Dataformatter.format (temp); REturn data; ]]> </fx:Script> <fx:Declarations> <!--format digital--> <mx:numberformatter id= "Dataformatter" pre cision= "2" rounding= "Up"/> </fx:Declarations> <mx:vbox width= "100%" height= "100%" paddingbottom= "10" paddingleft= "paddingright=" paddingtop= "ten" horizontalalign= "center" > <mx:datagrid id= "DataGrid" width= "100%" height= "90%" dataprovider= "{Gridarray}" textalign= "center" > <mx:columns> <mx:datagridcolumn headertext= "Week" datafield= "Week"/> <mx:datagridcolumn headertext= "Apple" datafield= "apple"/> Atagridcolumn headertext= "ratio" datafield= "rate" labelfunction= "Formatdatagrid"/> </mx:columns> </mx:d Atagrid> </mx:VBox> </s:Application>
3, the implementation of the results