The NumberFormatter class formats the decimal rounding and precision, thousand separator and negative sign.
The NumberFormatter class formats the decimal rounding and precision, thousand separator and negative sign.The NumberFormatter class formats the decimal rounding
and precision, thousand separator and negative sign. for
example,203.4567=203.456 . You can use the precision property for decimal
length. 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 NumberFormatter is <mx:NumberFormatter>.
You will be declare a formatter in <fx:Declarations> tag.
<?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 = numValidate.validate(); if (result.type==ValidationResultEvent.VALID) { numval.text= numberFormatter.format(numtxt.text); } else { numval.text= "Invalid Number"; } } ]]> </fx:Script> <fx:Declarations> <mx:NumberFormatter id="numberFormatter" precision="3" useThousandsSeparator="true" useNegativeSign="true"/> <mx:NumberValidator id="numValidate" source="{numtxt}" property="text" allowNegative="true" domain="real"/> </fx:Declarations> <s:Panel title="NumberValidator Example" width="506"> <mx:Form backgroundColor="#096465" width="504"> <mx:FormItem label="Enter number:" color="#FFFFFF" fontFamily="verdana"> <s:TextInput id="numtxt" text="" width="100%" color="#000000" fontFamily="verdana"/> </mx:FormItem> <mx:FormItem label="Formatted Value: " color="#FFFFFF" fontFamily="verdana"> <s:Label id="numval" color="#FFFFFF" fontFamily="verdana"/> </mx:FormItem> <mx:FormItem> <s:Button label="Format" click="checkFormat();"/> </mx:FormItem> </mx:Form> </s:Panel> </s:Application> |
To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.