Class sap.ui.core.format.NumberFormatModule: sap/ui/core/format/NumberFormat

extends Object

The NumberFormat is a static class for formatting and parsing numeric values according to a set of format options.

Namespaces & Classes
RoundingModeSpecifies a rounding behavior for numerical operations capable of discarding precision.
Constructor Summary
new sap.ui.core.format.NumberFormat(oFormatOptions?)Constructor for NumberFormat - must not be used: To get a NumberFormat instance, please use getInstance, getFloatInstance or getIntegerInstance.
Method Summary
sap.ui.core.format.NumberFormat.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.ui.core.format.NumberFormat with name sClassName and enriches it with the information contained in oClassInfo.
sap.ui.core.format.NumberFormat.getCurrencyInstance(oFormatOptions?, oLocale?)Get a currency instance of the NumberFormat, which can be used for formatting.
sap.ui.core.format.NumberFormat.getFloatInstance(oFormatOptions?, oLocale?)Get a float instance of the NumberFormat, which can be used for formatting.
sap.ui.core.format.NumberFormat.getIntegerInstance(oFormatOptions?, oLocale?)Get an integer instance of the NumberFormat, which can be used for formatting.
sap.ui.core.format.NumberFormat.getMetadata()Returns a metadata object for class sap.ui.core.format.NumberFormat.
sap.ui.core.format.NumberFormat.getPercentInstance(oFormatOptions?, oLocale?)Get a percent instance of the NumberFormat, which can be used for formatting.
format(oValue, sMeasure?)Format a number according to the given format options.
parse(sValue)Parse a string which is formatted according to the given format options.
Methods borrowed from class sap.ui.base.Object
Constructor Detail
new sap.ui.core.format.NumberFormat(oFormatOptions?)
Constructor for NumberFormat - must not be used: To get a NumberFormat instance, please use getInstance, getFloatInstance or getIntegerInstance.
Parameters:
{object}oFormatOptions? The option object which support the following parameters. If no options is given, default values according to the type and locale settings are used.
{int}oFormatOptions.minIntegerDigits? defines minimal number of non-decimal digits
{int}oFormatOptions.maxIntegerDigits? defines maximum number of non-decimal digits
{int}oFormatOptions.minFractionDigits? defines minimal number of decimal digits
{int}oFormatOptions.maxFractionDigits? defines maximum number of decimal digits
{int}oFormatOptions.decimals? defines the number of decimal digits
{int}oFormatOptions.shortDecimals? defines the number of decimal in the shortified format string. If this isn't specified, the 'decimals' options is used
{int}oFormatOptions.shortLimit? only use short number formatting for values above this limit
{int}oFormatOptions.precision? defines the number precision, number of decimals is calculated dependent on the integer digits
{string}oFormatOptions.pattern? CLDR number pattern which is used to format the number
{boolean}oFormatOptions.groupingEnabled? defines whether grouping is enabled (show the grouping separators)
{string}oFormatOptions.groupingSeparator? defines the used grouping separator
{int}oFormatOptions.groupingSize? defines the grouping size in digits, the default is three
{int}oFormatOptions.groupingBaseSize? defines the grouping base size in digits, in case it is different from the grouping size (e.g. indian grouping)
{string}oFormatOptions.decimalSeparator? defines the used decimal separator
{string}oFormatOptions.plusSign? defines the used plus symbol
{string}oFormatOptions.minusSign? defines the used minus symbol
{boolean}oFormatOptions.parseAsString? @since 1.28.2 defines whether to output string from parse function in order to keep the precision for big numbers. Numbers in scientific notation are parsed back to the standard notation. For example ".5e-3" is parsed to "0.0005".
{string}oFormatOptions.style? defines the style of format. Valid values are 'short, 'long' or 'standard' (based on CLDR decimalFormat). Numbers are formatted into compact forms when it's set to 'short' or 'long'.
{sap.ui.core.format.NumberFormat.RoundingMode}oFormatOptions.roundingMode? specifies a rounding behavior for discarding the digits after the maximum fraction digits defined by maxFractionDigits. Rounding will only be applied, if the passed value if of type number. This can be assigned by value in RoundingMode or a function which will be used for rounding the number. The function is called with two parameters: the number and how many decimal digits should be reserved.
{boolean}oFormatOptions.showMeasure? defines whether the measure according to the format is shown in the formatted string
{boolean}oFormatOptions.currencyCode? defines whether the currency is shown as code in currency format. The currency symbol is displayed when this is set to false and there's symbol defined for the given currency code.
{string}oFormatOptions.currencyContext? It can be set either with 'standard' (the default value) or with 'accounting' for an accounting specific currency display
{number}oFormatOptions.emptyString? @since 1.30.0 defines what empty string is parsed as and what is formatted as empty string. The allowed values are only NaN, null or 0. The 'format' and 'parse' are done in a symmetric way which means when this parameter is set to NaN, empty string is parsed as NaN and NaN is formatted as empty string.
Method Detail
sap.ui.core.format.NumberFormat.extend(sClassName, oClassInfo?, FNMetaImpl?): function
Creates a new subclass of class sap.ui.core.format.NumberFormat with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.base.Object.extend.

Parameters:
{string}sClassName Name of the class being created
{object}oClassInfo? Object literal with information about the class
{function}FNMetaImpl? Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
{function} Created class / constructor function
sap.ui.core.format.NumberFormat.getCurrencyInstance(oFormatOptions?, oLocale?): sap.ui.core.format.NumberFormat
Get a currency instance of the NumberFormat, which can be used for formatting.

If no locale is given, the currently configured formatLocale will be used.

This instance has HALF_AWAY_FROM_ZERO set as default rounding mode. Please set the roundingMode property in oFormatOptions to change the default value.

Parameters:
{object}oFormatOptions? Object which defines the format options
{sap.ui.core.Locale}oLocale? Locale to get the formatter for
Returns:
{sap.ui.core.format.NumberFormat} integer instance of the NumberFormat
sap.ui.core.format.NumberFormat.getFloatInstance(oFormatOptions?, oLocale?): sap.ui.core.format.NumberFormat
Get a float instance of the NumberFormat, which can be used for formatting.

If no locale is given, the currently configured formatLocale will be used.

This instance has HALF_AWAY_FROM_ZERO set as default rounding mode. Please set the roundingMode property in oFormatOptions to change the default value.

Parameters:
{object}oFormatOptions? Object which defines the format options
{sap.ui.core.Locale}oLocale? Locale to get the formatter for
Returns:
{sap.ui.core.format.NumberFormat} float instance of the NumberFormat
sap.ui.core.format.NumberFormat.getIntegerInstance(oFormatOptions?, oLocale?): sap.ui.core.format.NumberFormat
Get an integer instance of the NumberFormat, which can be used for formatting.

If no locale is given, the currently configured formatLocale will be used.

This instance has TOWARDS_ZERO set as default rounding mode. Please set the roundingMode property in oFormatOptions to change the default value.

Parameters:
{object}oFormatOptions? Object which defines the format options
{sap.ui.core.Locale}oLocale? Locale to get the formatter for
Returns:
{sap.ui.core.format.NumberFormat} integer instance of the NumberFormat
sap.ui.core.format.NumberFormat.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.ui.core.format.NumberFormat.
Returns:
{sap.ui.base.Metadata} Metadata object describing this class
sap.ui.core.format.NumberFormat.getPercentInstance(oFormatOptions?, oLocale?): sap.ui.core.format.NumberFormat
Get a percent instance of the NumberFormat, which can be used for formatting.

If no locale is given, the currently configured formatLocale will be used.

This instance has HALF_AWAY_FROM_ZERO set as default rounding mode. Please set the roundingMode property in oFormatOptions to change the default value.

Parameters:
{object}oFormatOptions? Object which defines the format options
{sap.ui.core.Locale}oLocale? Locale to get the formatter for
Returns:
{sap.ui.core.format.NumberFormat} integer instance of the NumberFormat
format(oValue, sMeasure?): string
Format a number according to the given format options.
Parameters:
{number|array}oValue the number to format or an array which contains the number to format and the sMeasure parameter
{string}sMeasure? a measure which has an impact on the formatting
Returns:
{string} the formatted output value
parse(sValue): number|array
Parse a string which is formatted according to the given format options.
Parameters:
{string}sValue the string containing a formatted numeric value
Returns:
{number|array} the parsed value or an array which contains the parsed value and the currency code (symbol) when the NumberFormat is a currency instance