tags:

views:

3041

answers:

2
+1  Q: 

Flex Number Format

Hi all,

I want to format a number in indian format.

for example,

x= 123456 should be formatted as 1,23,456.

How can i do it in flex?

Thanks,

+1  A: 

Use the numberformatter.

<mx:NumberFormatter id="myFormatter"
    decimalSeparatorFrom="."
    decimalSeparatorTo="."
    precision="-1"
    rounding="none"
    thousandsSeparatorFrom=","
    thousandsSeparatorTo=","
    useNegativeSign="true"
    useThousandsSeparator="true"/>

actionscript code

x = myFormatter.format(x);
Shua
+1  A: 

from http://livedocs.adobe.com/flex/2/langref/mx/formatters/NumberFormatter.html

Package mx.formatters Class public class NumberFormatter Inheritance NumberFormatter Inheritance Formatter Inheritance Object

The NumberFormatter class formats a valid number by adjusting the decimal rounding and precision, the thousands separator, and the negative sign.

If you use both the rounding and precision properties, rounding is applied first, and then you set the decimal length by using the specified precision value. This lets you round a number and still have a trailing decimal; for example, 303.99 = 304.00.

If an error occurs, an empty String is returned and a String describing the error is saved to the error property. The error property can have one of the following values:

  • "Invalid value" means an invalid numeric value is passed to the format() method. The value should be a valid number in the form of a Number or a String.
  • "Invalid format" means one of the parameters contain an unusable setting.

MXML Syntaxcollapsed Show MXML Syntax expanded Hide MXML Syntax

The tag inherits all of the tag attributes of its superclass, and adds the following tag attributes:

  <mx:NumberFormatter
    decimalSeparatorFrom="."
    decimalSeparatorTo="."
    precision="-1"
    rounding="none|up|down|nearest"
    thousandsSeparatorFrom=","
    thousandsSeparatorTo=","
    useNegativeSign="true|false"
    useThousandsSeparator="true|false"/>
joe