Flex中对表格中某列的值举办数字名目化保存两位

一般的,表格中展示的比率,比拟率的处理惩罚是:保存两位小数,并向上保存

2、实现实例

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" fontSize="12" fontFamily="微软雅黑"> <s:layout> <s:BasicLayout/> </s:layout> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.events.FlexEvent; [Bindable] //表格数据绑定 private var gridArray:ArrayCollection = new ArrayCollection([ {week:"礼拜一",apple:"3676",rate:"0.7868"}, {week:"礼拜二",apple:"4534",rate:"0.65454"}, {week:"礼拜三",apple:"6758",rate:"0.876454"}, {week:"礼拜四",apple:"9808",rate:"0.34224"}, {week:"礼拜五",apple:"6567",rate:"0.9876523"}, {week:"礼拜六",apple:"9000",rate:"0.566777"}, {week:"礼拜日",apple:"4533",rate:"0.988787"} ]); /** * 对表格中的比率举办名目化 */ private function formatDataGrid(item:Object,column:DataGridColumn):String { var temp:Number = item.rate; var data:String = dataFormatter.format(temp); return data; } ]]> </fx:Script> <fx:Declarations> <!--名目化数字--> <mx:NumberFormatter precision="2" rounding="up"/> </fx:Declarations> <mx:VBox paddingBottom="10" paddingLeft="10" paddingRight="20" paddingTop="10" horizontalAlign="center"> <mx:DataGrid dataProvider="{gridArray}" textAlign="center"> <mx:columns> <mx:DataGridColumn headerText="礼拜" dataField="week"/> <mx:DataGridColumn headerText="苹果" dataField="apple"/> <mx:DataGridColumn headerText="比率" dataField="rate" labelFunction="formatDataGrid"/> </mx:columns> </mx:DataGrid> </mx:VBox> </s:Application>

3、实现功效

Flex中对表格中某列的值举行数字款式化生存两位

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsdpxz.html