# Class NumberFormatter

A helper class for formatting and parsing numbers.

#### Hierarchy (view full)

- SerializableBase<NumberFormatterProperties>
  - NumberFormatter

#### Implements

- NumberSettings

#####
Index

### Constructors

constructor

### Properties

locale

### Accessors

currency
defaultFormat
defaultParseFormat
fractionalDigits

### Methods

_getSerializableProperties
_toPropertyDef
assignProperties
assignPropertiesAsync
finishAssignProperties
format
getDefault
getDefaults
getSerializableProperties
parse
toJSON

##
Constructors

### constructor

- new NumberFormatter(_properties?): NumberFormatter

- #### Parameters

  - `Optional`_properties: NumberFormatterProperties

  #### Returns NumberFormatter

  Inherited from SerializableBase.constructor

##
Properties

### locale

locale: string

The locale to use when formatting & parsing the number. If not specified, the current locale is used (see locale module).

##
Accessors

### currency

- get currency(): string

- The 3-letter ISO 4217 currency code (e.g "USD", "CAD"). Required when formatting a number using NumberFormat.CURRENCY or NumberFormat.ACCOUNTING.

  #### Returns string

  Implementation of NumberSettings.currency

- set currency(currency): void

- The 3-letter ISO 4217 currency code (e.g "USD", "CAD"). Required when formatting a number using NumberFormat.CURRENCY or NumberFormat.ACCOUNTING.

  #### Parameters

  - currency: string

  #### Returns void

  Implementation of NumberSettings.currency

### defaultFormat

- get defaultFormat(): string

- The default format for formatting numbers. See utilities/format/number!NumberFormatter.format.

  #### Returns string

  Implementation of NumberSettings.defaultFormat

- set defaultFormat(defaultFormat): void

- The default format for formatting numbers. See utilities/format/number!NumberFormatter.format.

  #### Parameters

  - defaultFormat: string

  #### Returns void

  Implementation of NumberSettings.defaultFormat

### defaultParseFormat

- get defaultParseFormat(): string

- Either a single format, or one of several possible formats that the input is expected to be in. If specified, the input must exactly match. The syntax is the same as for utilities/format/number!NumberFormatter.format.

  #### Returns string

  Implementation of NumberSettings.defaultParseFormat

- set defaultParseFormat(defaultParseFormat): void

- Either a single format, or one of several possible formats that the input is expected to be in. If specified, the input must exactly match. The syntax is the same as for utilities/format/number!NumberFormatter.format.

  #### Parameters

  - defaultParseFormat: string

  #### Returns void

  Implementation of NumberSettings.defaultParseFormat

### fractionalDigits

- get fractionalDigits(): number

- The number of digits to show after the decimal point. If unspecified, an appropriate value is determined based on the locale and currency.

  #### Returns number

  Implementation of NumberSettings.fractionalDigits

- set fractionalDigits(fractionalDigits): void

- The number of digits to show after the decimal point. If unspecified, an appropriate value is determined based on the locale and currency.

  #### Parameters

  - fractionalDigits: number

  #### Returns void

  Implementation of NumberSettings.fractionalDigits

##
Methods

### `Protected`_getSerializableProperties

- _getSerializableProperties(): PropertyDefs<NumberFormatterProperties>

- The property keys and their metadata that are used to implement serializing and deserializing the class instance.

  #### Returns PropertyDefs<NumberFormatterProperties>

  Overrides SerializableBase._getSerializableProperties

### `Protected`_toPropertyDef

- _toPropertyDef<T>(def): PropertyDef<T>

- Converts the value to a PropertyDef object.

  #### Type Parameters

  - T

  #### Parameters

  - def: PropertyDefSerializeMode | PropertyDefSerializeMode[] | PropertyDef<T>

    The value to convert.

  #### Returns PropertyDef<T>

  Inherited from SerializableBase._toPropertyDef

### assignProperties

- assignProperties(properties): void

- Sets the properties for this item.

  #### Parameters

  - properties: Partial<NumberFormatterProperties>

    A plain object containing property values to set, keyed by property name.

  #### Returns void

  Inherited from SerializableBase.assignProperties

### assignPropertiesAsync

- assignPropertiesAsync(properties): Promise<void>

- Sets the properties for this item.

  This version will also await any asynchronous logic that is needed to set the properties.

  #### Parameters

  - properties: Partial<NumberFormatterProperties>

    A plain object containing property values to set, keyed by property name.

  #### Returns Promise<void>

  Inherited from SerializableBase.assignPropertiesAsync

### finishAssignProperties

- finishAssignProperties(): Promise<void>

- Waits for all deserialization logic initiated thus far to finish, whether invoked by passing properties into the constructor, or by invoking `assignProperties()` or `assignPropertiesAsync()`.

  #### Returns Promise<void>

  Inherited from SerializableBase.finishAssignProperties

### format

- format(format, num): string

- See format.

  #### Parameters

  - format: string
  - num: number

  #### Returns string

- format(options, num): string

- #### Parameters

  - options: FormatOptions
  - num: number

  #### Returns string

- format(num): string

- #### Parameters

  - num: number

  #### Returns string

### getDefault

- getDefault<K>(key): NumberFormatterProperties[K]

- Gets the default value of an object's property.

  #### Type Parameters

  - K extends keyof NumberFormatterProperties

  #### Parameters

  - key: K

    The property of the object for which to get the default value.

  #### Returns NumberFormatterProperties[K]

  Inherited from SerializableBase.getDefault

### getDefaults

- getDefaults(): NumberFormatterProperties

- Gets the object's default property values.

  #### Returns NumberFormatterProperties

  Inherited from SerializableBase.getDefaults

### getSerializableProperties

- getSerializableProperties(serializeMode?): PropertyDefs<NumberFormatterProperties>

- Returns the serializable properties.

  #### Parameters

  - serializeMode: SerializeMode = "all"

    Optional. If specified, only properties that support the given serialization mode will be returned.

  #### Returns PropertyDefs<NumberFormatterProperties>

  Inherited from SerializableBase.getSerializableProperties

### parse

- parse(input): number

- See parse.

  #### Parameters

  - input: unknown

  #### Returns number

- parse(format, input): number

- #### Parameters

  - format: string | string[]
  - input: unknown

  #### Returns number

- parse(options, input): number

- #### Parameters

  - options: ParseOptions
  - input: unknown

  #### Returns number

### toJSON

- toJSON(serializeMode?): NumberFormatterProperties

- Returns a serializable representation of the item.

  #### Parameters

  - serializeMode: SerializeMode = "all"

    If specified, only properties that are appropriate for the given mode are returned. Otherwise, all properties will be serialized.

  #### Returns NumberFormatterProperties

  Inherited from SerializableBase.toJSON