Last updated

API / geotoolkit / util / NumberFormat / NumberFormat

Class: NumberFormat

util.NumberFormat.NumberFormat

Defines base class for formatting numbers based on Java NumberFormatter.
User can also use DecimalFormat which allows creating a custom format as well.

Example

// locale parameter can be used to specify 'Norway' as shown below. 'fr', 'ru', 'us', 'de' ... are also available.
const number = new NumberFormat({'locale': 'no'});
number.setMaximumFractionDigits(2);
number.format(5000.123); // '5 000,12'

Hierarchy

Table of contents

Constructors
Methods
Css Properties
Name Type Description
fulllocalebooleanSpecify format how to provide locale
grouplengthnumberSpecify group length of numbers
localestringFormat locale
localeLocaleFormat locale
locale-localestringThe name of the locale
locale-numberformatNumberFormatInfoDefines number format
locale-numberformat-decstringDefines decimal symbol
locale-numberformat-groupstringDefines group symbol
locale-numberformat-infinitystringDefines infinity text
locale-numberformat-negstringDefines negative symbol
maximumfractiondigitsnumberSpecify maximum fraction digits
minimumfractiondigitsnumberSpecify minimum fraction digits, have to be less or equal to maximumfractiondigits
roundbooleanRound number

Contents

Constructors

new NumberFormat(options)

new NumberFormat(options?)

Parameters

Name Type
Optional optionsOptions

Overrides

Format.constructor

Methods

clone

clone(): Format

All inheritors should implement copy constructor or provide custom implementation for this method

Returns

Format

clone

Inherited from

Format.clone


copyConstructor

Protected copyConstructor(src): NumberFormat

copy constructor

Parameters

Name Type Description
srcNumberFormatSource to copy from

Returns

NumberFormat

this

Overrides

Format.copyConstructor


format

format(number): string

Formats number to string

Parameters

Name Type Description
numbernumbernumber to be formatted

Returns

string

Overrides

Format.format


getClassName

getClassName(): string

Returns

string

Inherited from

Format.getClassName


getLocalFormatData

Protected getLocalFormatData(locale?): NumberFormatInfo

Return object, which contains 'dec', 'group', 'neg' symbols

Parameters

Name Type Description
Optional localestring | Localelocale

Returns

NumberFormatInfo


getLocale

getLocale(): Locale

Return the current locale

Returns

Locale


getMaximumFractionDigits

getMaximumFractionDigits(number?): number

Return maximum faction digits

Parameters

Name Type Description
Optional numbernumberan optional number to get maximum fraction digits

Returns

number


getMinimumFractionDigits

getMinimumFractionDigits(number?): number

Return minimum faction digits

Parameters

Name Type Description
Optional numbernumberan optional number to get minimum fraction digits

Returns

number


getProperties

getProperties(): OptionsOut

Gets all the properties pertaining to this object

Returns

OptionsOut

properties pertaining to this object

Overrides

Format.getProperties


setLocale

setLocale(locale): NumberFormat

Sets locale

Parameters

Name Type Description
localestring | Localelocale

Returns

NumberFormat

this


setMaximumFractionDigits

setMaximumFractionDigits(digits): NumberFormat

Return maximum fraction digits

Parameters

Name Type Description
digitsnumbermaximum fraction digits

Returns

NumberFormat

this


setMinimumFractionDigits

setMinimumFractionDigits(digits): NumberFormat

Return minimum fraction digits

Parameters

Name Type Description
digitsnumberminimum fraction digits

Returns

NumberFormat

this


setProperties

setProperties(properties?): NumberFormat

Sets properties

Parameters

Name Type Description
Optional propertiesOptionsproperties pertaining to this object

Returns

NumberFormat

this

Overrides

Format.setProperties


toFixed

Protected toFixed(number, decimalPlaces?): string

Convert number to format with fixed point

Parameters

Name Type Description
numbernumbernumber to be converted
Optional decimalPlacesnumbernumber of decimal places this number can have

Returns

string


getClassName

Static getClassName(): string

Returns

string

Inherited from

Format.getClassName


getInstance

Static getInstance(locale?): NumberFormat

Return instance of the number format

Parameters

Name Type Description
Optional localestringlocale of formatter. Locals is not supported for now.

Returns

NumberFormat

instance of the number format