Home Tutorial Flex Flex4 Components CurrencyFormatter in Flex4

 
 

CurrencyFormatter in Flex4
Posted on: June 2, 2010 at 12:00 AM
The CurrencyFormatter class formats a number in a currency value.

CurrencyFormatter in Flex4:

The CurrencyFormatter class formats a number in a currency value. It formatted the decimal rounding and precision, thousand separator and negative sign. you can set the currency symbol by using currencySymbol property. You can also set the symbol alignment left, right by using alignSymbol property. If an error occurs this error is saved to the error property. The error property has two types of error values: Invalid value, Invalid format. The tag of CurrencyFormatter is <mx:CurrencyFormatter>. You will be declare a formatter in <fx:Declarations> tag.

Example:

<?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"

minWidth="955" minHeight="600">

<fx:Script>

<![CDATA[

import mx.events.ValidationResultEvent;

private var result:ValidationResultEvent;

private function checkFormat():void {

result = numValue.validate();

if (result.type==ValidationResultEvent.VALID) {

var num:Number=Number(rupeestxt.text);

rupeeslbl.text= irupFormatter.format(num);

}

else {

rupeeslbl.text="Invalid Value";

}

}

]]>

</fx:Script>

<fx:Declarations>

<mx:CurrencyFormatter id="irupFormatter" precision="2" currencySymbol="Rs."

 decimalSeparatorFrom="." rounding="nearest"

decimalSeparatorTo="." useNegativeSign="true" useThousandsSeparator="true"

 alignSymbol="left"/>

<mx:NumberValidator id="numValue" source="{rupeestxt}" property="text"

 allowNegative="true" domain="real"/>

</fx:Declarations>

<s:Panel title="CurrencyFormatter Example" width="545">

<mx:Form backgroundColor="#096465" width="543">

<mx:FormItem label="Enter amount(Rs):" color="#FFFFFF" fontFamily="verdana">

<s:TextInput id="rupeestxt" width="100%" color="#000000" fontFamily="verdana"/>

</mx:FormItem>

<mx:FormItem label="Formatted amount(Rs): " color="#FFFFFF" fontFamily="verdana">

<s:Label id="rupeeslbl" text="" color="#FFFFFF" fontFamily="verdana"/>

</mx:FormItem>

<mx:FormItem>

<s:Button label="Format" click="checkFormat();"/>

</mx:FormItem>

</mx:Form>

</s:Panel>

</s:Application>

Output:

Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

Download this code

Related Tags for CurrencyFormatter in Flex4:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.