简体   繁体   中英

Flex Number Format

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,

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);

I guess one need to build his/her own number formatter to do this task. Simply using the NumberFormatter will only result into following

123,456 and not 1,23,456 (i.e. the Indian style number formatting)

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"/>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM