In Flex, the value of a column in a table is digitally formatted to preserve a two-digit decimal _flex

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.