Flex中對(duì)表格中某列的值進(jìn)行數(shù)字格式化保留兩位小數(shù)
更新時(shí)間:2014年10月21日 17:01:53 投稿:whsnow
表格中展示的比率,對(duì)比率的處理是:保留兩位小數(shù),并向上保留。通過(guò)對(duì)某列的值進(jìn)行數(shù)字格式化來(lái)實(shí)現(xiàn)保留兩位小數(shù)
1、問(wèn)題背景
一般的,表格中展示的比率,對(duì)比率的處理是:保留兩位小數(shù),并向上保留
2、實(shí)現(xiàn)實(shí)例
<?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"
width="100%" height="100%" fontSize="12"
fontFamily="微軟雅黑">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
//表格數(shù)據(jù)綁定
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"}
]);
/**
* 對(duì)表格中的比率進(jìn)行格式化
*/
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>
<!--格式化數(shù)字-->
<mx:NumberFormatter id="dataFormatter" precision="2" rounding="up"/>
</fx:Declarations>
<mx:VBox width="100%" height="100%" paddingBottom="10" paddingLeft="10" paddingRight="20"
paddingTop="10" horizontalAlign="center">
<mx:DataGrid id="dataGrid" width="100%" height="90%" dataProvider="{gridArray}" textAlign="center">
<mx:columns>
<mx:DataGridColumn headerText="星期" dataField="week"/>
<mx:DataGridColumn headerText="蘋(píng)果" dataField="apple"/>
<mx:DataGridColumn headerText="比率" dataField="rate" labelFunction="formatDataGrid"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
</s:Application>
3、實(shí)現(xiàn)結(jié)果

相關(guān)文章
Flex中在Tree綁定數(shù)據(jù)后自動(dòng)展開(kāi)樹(shù)節(jié)點(diǎn)的方法
使用Tree組件在綁定數(shù)據(jù)后自動(dòng)展開(kāi)所有樹(shù)型節(jié)點(diǎn)(不需要用戶(hù)再自己點(diǎn)擊展開(kāi)節(jié)點(diǎn),會(huì)方 便許多),接下來(lái)為大家介紹下具體的實(shí)現(xiàn)2014-01-01
flex實(shí)現(xiàn)股票行情走勢(shì)圖示例代碼
股票行情走勢(shì)圖在flex中也可以實(shí)現(xiàn)了,具體步驟及代碼如下,感興趣的朋友可以參考下,或許有所幫助2013-10-10
FLEX 獲取DataGrid行號(hào)和列號(hào)示例代碼
獲取DataGrid行號(hào)和列號(hào)在使用過(guò)程中還是蠻實(shí)用的,下面為大家詳細(xì)介紹下FLEX是如何做到的,感興趣的朋友可以了解下2013-09-09
js調(diào)用Flex中的方法并向flex中傳參及flex調(diào)用js示例
本文為大家詳細(xì)介紹喜愛(ài)js調(diào)用Flex中的方法以及向flex中傳參與flex調(diào)用js,具體示例如下,感興趣的朋友不妨參考下,希望對(duì)大家有所幫助2013-07-07
Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表實(shí)現(xiàn)代碼
Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表(支持多行同時(shí)拖拽,重復(fù)數(shù)據(jù)不重得添加,添加了圖表右鍵菜單)等等,感興趣的朋友可以了解下啊,或許對(duì)你有所幫助2013-01-01

