CurrencyFormatter in Flex4


 

CurrencyFormatter in Flex4

The CurrencyFormatter class formats a number in a currency value.

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>

0

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

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

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

1

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

</mx:FormItem>

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

2

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

</mx:FormItem>

<mx:FormItem>

3

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

</mx:FormItem>

</mx:Form>

4

</s:Panel>

</s:Application>

Output:

5

Running Application:

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

Download this code

6

Ads