2 Replies Latest reply on Jul 14, 2010 3:52 AM by KevMull

    CurrencyFormatter In Datagrid Shows Zero For Values less than 1.00

    KevMull Level 1

      I'm using the CurrencyFormatter in my datagrid but for some reason values less than 1.00 (i.e. 0.52, 0.75 etc) show as £0.00.

      All other values are fine.

       

      Here is my ciode...

       

      <mx:CurrencyFormatter id="gbpFormat" alignSymbol="left" precision="2" currencySymbol="£" rounding="none"  useNegativeSign="false" />

       

      <mx:DataGridColumn headerText="Unit Price" dataField="unitPrice" textAlign="right"
                               labelFunction="price_labelFunc"  sortCompareFunction="price_sortCompareFunc"  />

       

      protected function price_labelFunc(item:Object, column:DataGridColumn):String
              {
                  return gbpFormat.format(item.unitPrice);
              }

       

       

      The data is via an XML which typically looks this...

       

      <unitPrice>0.52</unitPrice>

       

      Using Flex 3 (sdk 3.6)

       

      Many Thanks

        • 1. Re: CurrencyFormatter In Datagrid Shows Zero For Values less than 1.00
          rtalton Level 4

          I had the same issue with your code until I used an XMLListCollection as the dataprovider.

          Here is my full sample code:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

           

          <mx:Script>
              <![CDATA[       
                 
                  private function price_labelFunc(item:Object, column:DataGridColumn):String{
                      trace(item);
                      return gbpFormat.format(item);
                  }
                 
              ]]>
          </mx:Script>

           

          <mx:XML id="xmlData">
              <prices>
                  <unitPrice>1.52</unitPrice>
                  <unitPrice>0.52</unitPrice>
                  <unitPrice>0.55</unitPrice>
                  <unitPrice>0.75</unitPrice>
              </prices>
          </mx:XML>

           

          <mx:XMLListCollection id="XMLListData"
                      source="{xmlData.unitPrice}" />

           


          <mx:DataGrid dataProvider="{XMLListData}"
               >   
              <mx:columns>
                  <mx:DataGridColumn headerText="Unit Price"    
                      dataField="unitPrice"
                      textAlign="right"
                      labelFunction="price_labelFunc"/>
              </mx:columns>
          </mx:DataGrid>

           

          <mx:CurrencyFormatter id="gbpFormat"
              alignSymbol="left"
              precision="2"
              currencySymbol="£"
              rounding="none"
              useNegativeSign="false" />
            
          </mx:Application>

          • 2. Re: CurrencyFormatter In Datagrid Shows Zero For Values less than 1.00
            KevMull Level 1

            Many Thanks

             

            The proble was in my resultHander I was declaring unitPrice as a Number wher I should have left it blank..

             

            storeProductItem1.unitPrice = event.result.ajaxResponse.objectDetails.storeProductItem.unitPrice ;

             

            WAS (incorrectly)

             

            storeProductItem1.unitPrice = event.result.ajaxResponse.objectDetails.storeProductItem.unitPrice as Number ;