How to format currency data field in Flex

I have an xml file providing data for a datagrid in Flex 2, which includes an unformatted Price field (i.e.: it's just a number). Can someone tell me how I take this data field and format it - add a currency symbol, put in thousands of separators, etc. Thank you S.

+3
source share
3 answers

As mentioned above, a simple way to do this would be to add a Function label to the specified column and format the data there.

Often I find it much easier to work with objects and then directly XML, so usually, if I get XML from a function, I would create an object and a parser for this XML, and you can also format the data inside the parser if you like .

Another way to handle this would be inside the itemRenderer. Example:

<mx:DataGridColumn id="dgc" headerText="Money" editable="false">
    <mx:itemRenderer>
      <mx:Component>
         <mx:HBox horizontalAlign="right">
        <mx:CurrencyFormatter id="cFormat" precision="2" currencySymbol="$" useThousandsSeparator="true"/>
            <mx:Label id="lbl" text="{cFormat.format(data)}" />
         </mx:HBox>
      </mx:Component>
    </mx:itemRenderer>
</mx:DataGridColumn>
+1
source

Thank you very much for your answers ... they helped a lot.

In the end, I went for a solution that included the following three elements:

<mx:DataGridColumn headerText="Price" textAlign="right"  labelFunction="formatCcy" width="60"/>

public function formatCcy(item:Object, column:DataGridColumn):String
        {
         return euroPrice.format(item.price);
        }

<mx:CurrencyFormatter id="euroPrice" precision="0" 
    rounding="none"
    decimalSeparatorTo="."
    thousandsSeparatorTo=","
    useThousandsSeparator="true"
    useNegativeSign="true"
    currencySymbol="€"
    alignSymbol="left"/>

I don't know if this is the right solution, but it seems to work (for now), Thanks again, S ...

+4
source

CurrencyFormatter

. Flex 2. .

label DataGrid .

0

Source: https://habr.com/ru/post/1697925/


All Articles