1 Reply Latest reply on Sep 24, 2009 3:01 PM by dimiorla

    CurrencyFormatter and grand total of column


      Hey everyone,


      I think I have have two bug’s or arror in my code, with the folowing application

      The grand total of column Cost does not execute with creationComplete but I have to call it throu the button

      And whean I clik in a row of Cost column and clik away the amound gets two extra digits, it has to do with precision="2" of the CurrencyFormatter dut how do I keep the format and not the dug.


      Thanks in advance,

      Dimitris Orlandos.


      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application  creationComplete="loadData()" styleName="plain" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="376" xmlns:ordersopenservice="services.ordersopenservice.*">



                        import mx.events.FlexEvent;

                        import mx.controls.Alert;

                        import mx.collections.ArrayCollection;


      private function loadData():void






      private function initApp():void


                        dataGrid.dataProvider = new ArrayCollection([

                          {Type:'Normal', Desc:'Normal 20/20', Cost:0},

                          {Type:'None', Desc:'Player has no optical receptors', Cost:-2},

                          {Type:'Enhanced', Desc:'Enhanced Vision', Cost:5},

                          {Type:'Infrared', Desc:'Player can see heat sources', Cost:5}





      public function formatPrice(item:Object, column:DataGridColumn):String


                              var returnValue:String = setCurrencyFormat.format(item.Cost);

                              return returnValue;




                                   private var totalColumn:Number = 0;

                                   private function calculateTotalColumn():void


                                         for each (var row:Object in dataGrid.dataProvider)


                                   totalColumn += Number(row.Cost);







           <mx:CurrencyFormatter id="setCurrencyFormat" precision="2" rounding="none" decimalSeparatorTo=","

            thousandsSeparatorTo="." useThousandsSeparator="true" useNegativeSign="true" currencySymbol="" alignSymbol="left"/>


            <mx:Text text="{setCurrencyFormat.format(totalColumn)}" x="363" y="240" height="35"  fontWeight="bold" fontSize="16" id="text1" fontFamily="Eurostile" width="77" />


            <mx:Button id="b1"



                 x="352" y="298" />

            <mx:DataGrid id="dataGrid" editable="true" width="348" height="205" x="22" y="10">


                    <mx:DataGridColumn dataField="Type"/>

                    <mx:DataGridColumn dataField="Desc"/>

                    <mx:DataGridColumn dataField="Cost" labelFunction="formatPrice"/>








        • 1. Re: CurrencyFormatter and grand total of column
          dimiorla Level 1

          For everyone interested, this is my work around.

          If there is a better way please let me know


          private function calculateTotalColumn(evt:CollectionEvent):void


                 var totalColumn:Number = 0;

                 for each (var row:Object in OrdersOpenDataGrid.dataProvider)


                       totalColumn += Number(row.total_price);


                 text1.text = setCurrencyFormat.format(totalColumn.toFixed(2));




          <mx:CurrencyFormatter id="setCurrencyFormat" useNegativeSign="true" currencySymbol="€" alignSymbol="left"/>