Home Tutorial Flex Flex4 Components CurrencyFormatter in Flex4

 
 

Share on Google+Share on Google+
CurrencyFormatter in Flex4
Posted on: June 2, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for CurrencyFormatter in Flex4:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 2, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com