Packagemx.formatters
Classpublic class NumberFormatter
InheritanceNumberFormatter Inheritance Formatter

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:

MXML Syntaxexpanded Hide MXML Syntax

The <mx:NumberFormatter> 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"/>  
  

See also

mx.formatters.NumberBase
mx.formatters.NumberBaseRoundType


Public Properties
 PropertyDefined by
  decimalSeparatorFrom : String
Decimal separator character to use when parsing an input String.
NumberFormatter
  decimalSeparatorTo : String
Decimal separator character to use when outputting formatted decimal numbers.
NumberFormatter
 InheriteddefaultInvalidFormatError : String
[static] Error message for an invalid format string specified to the formatter.
Formatter
 InheriteddefaultInvalidValueError : String
[static] Error messages for an invalid value specified to the formatter.
Formatter
 Inheritederror : String
Description saved by the formatter when an error occurs.
Formatter
  precision : Object
Number of decimal places to include in the output String.
NumberFormatter
  rounding : String
Specifies how to round the number.
NumberFormatter
  thousandsSeparatorFrom : String
Character to use as the thousands separator in the input String.
NumberFormatter
  thousandsSeparatorTo : String
Character to use as the thousands separator in the output String.
NumberFormatter
  useNegativeSign : Object
If true, format a negative number by preceding it with a minus "-" sign.
NumberFormatter
  useThousandsSeparator : Object
If true, split the number into thousands increments by using a separator character.
NumberFormatter
Public Methods
 MethodDefined by
  
Constructor.
NumberFormatter
  
format(value:Object):String
Formats the number as a String.
NumberFormatter
Protected Methods
 MethodDefined by
 Inherited
This method is called when a Formatter is constructed, and again whenever the ResourceManager dispatches a "change" Event to indicate that the localized resources have changed in some way.
Formatter
Property detail
decimalSeparatorFromproperty
decimalSeparatorFrom:String  [read-write]

Decimal separator character to use when parsing an input String.

The default value is ".".

Implementation
    public function get decimalSeparatorFrom():String
    public function set decimalSeparatorFrom(value:String):void
decimalSeparatorToproperty 
decimalSeparatorTo:String  [read-write]

Decimal separator character to use when outputting formatted decimal numbers.

The default value is ".".

Implementation
    public function get decimalSeparatorTo():String
    public function set decimalSeparatorTo(value:String):void
precisionproperty 
precision:Object  [read-write]

Number of decimal places to include in the output String. You can disable precision by setting it to -1. A value of -1 means do not change the precision. For example, if the input value is 1.453 and rounding is set to NumberBaseRoundType.NONE, return a value of 1.453. If precision is -1 and you have set some form of rounding, return a value based on that rounding type.

The default value is -1.

Implementation
    public function get precision():Object
    public function set precision(value:Object):void
roundingproperty 
rounding:String  [read-write]

Specifies how to round the number.

In ActionScript, you can use the following constants to set this property: NumberBaseRoundType.NONE, NumberBaseRoundType.UP, NumberBaseRoundType.DOWN, or NumberBaseRoundType.NEAREST. Valid MXML values are "down", "nearest", "up", and "none".

The default value is NumberBaseRoundType.NONE.

Implementation
    public function get rounding():String
    public function set rounding(value:String):void

See also

thousandsSeparatorFromproperty 
thousandsSeparatorFrom:String  [read-write]

Character to use as the thousands separator in the input String.

The default value is ",".

Implementation
    public function get thousandsSeparatorFrom():String
    public function set thousandsSeparatorFrom(value:String):void
thousandsSeparatorToproperty 
thousandsSeparatorTo:String  [read-write]

Character to use as the thousands separator in the output String.

The default value is ",".

Implementation
    public function get thousandsSeparatorTo():String
    public function set thousandsSeparatorTo(value:String):void
useNegativeSignproperty 
useNegativeSign:Object  [read-write]

If true, format a negative number by preceding it with a minus "-" sign. If false, format the number surrounded by parentheses, for example (400).

The default value is true.

Implementation
    public function get useNegativeSign():Object
    public function set useNegativeSign(value:Object):void
useThousandsSeparatorproperty 
useThousandsSeparator:Object  [read-write]

If true, split the number into thousands increments by using a separator character.

The default value is true.

Implementation
    public function get useThousandsSeparator():Object
    public function set useThousandsSeparator(value:Object):void
Constructor detail
NumberFormatter()constructor
public function NumberFormatter()

Constructor.

Method detail
format()method
public override function format(value:Object):String

Formats the number as a String. If value cannot be formatted, return an empty String and write a description of the error to the error property.

Parameters
value:Object — Value to format.

Returns
String — Formatted String. Empty if an error occurs.