Formatting data with the formatter classes
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
private function calculate(event:Event):void
{
var result:Number = Number(priceTxt.text) * (Number(ivaTxt.text) / 100);
totalTxt.text = totalF.format(result.toString());
}
</mx:Script>
<mx:CurrencyFormatter id="totalF"
currencySymbol=""
precision="2"
decimalSeparatorFrom=","
decimalSeparatorTo=","
thousandsSeparatorFrom="."
thousandsSeparatorTo="."
useThousandsSeparator="true" />
<mx:Panel title="Formatter" width="477" height="252">
<mx:Form>
<mx:TextInput id="priceTxt"/>
<mx:TextInput id="ivaTxt"/>
<mx:FormItem label="">
<mx:Button label="Calculate" click="calculate(event)" />
</mx:FormItem>
</mx:Form>
<mx:ControlBar>
<mx:Label text="This is your value: " />
<mx:TextInput id="totalTxt" editable="false"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
Related examples in the same category