Version 3.18.1
Show:

Number Class

Number provides a set of utility functions to operate against Number objects.

Item Index

Methods

_buildParser

(
  • [prefix]
  • [suffix]
  • [separator]
  • [decimal]
)
Function private

Provided by the datatype-number-parse module.

Defined in number/js/number-parse.js:13

Returns a parsing function for the given configuration. It uses Y.cached so it expects the format spec separated into individual values. The method further uses closure to put together and save the regular expresssion just once in the outer function.

Parameters:

  • [prefix] String optional

    Prefix string to be stripped out.

  • [suffix] String optional

    Suffix string to be stripped out.

  • [separator] String optional

    Thousands separator to be stripped out.

  • [decimal] String optional

    Decimal separator to be replaced by a dot.

Returns:

Function:

Parsing function.

format

(
  • data
  • config
)
String

Takes a Number and formats to string for display to user.

Parameters:

  • data Number

    Number.

  • config Object

    (Optional) Optional configuration values:

    prefix {String}
    String prepended before each number, like a currency designator "$"
    decimalPlaces {Number}
    Number of decimal places to round. Must be a number 0 to 20.
    decimalSeparator {String}
    Decimal separator
    thousandsSeparator {String}
    Thousands separator
    suffix {String}
    String appended after each number, like " items" (note the space)

Returns:

String:

Formatted number for display. Note, the following values return as "": null, undefined, NaN, "".

parse

(
  • data
  • [config]
)
Number

Provided by the datatype-number-parse module.

Defined in number/js/number-parse.js:53

Converts data to type Number. If a config argument is used, it will strip the data of the prefix, the suffix and the thousands separator, if any of them are found, replace the decimal separator by a dot and parse the resulting string. Extra whitespace around the prefix and suffix will be ignored.

Parameters:

  • data String | Number | Boolean

    Data to convert. The following values return as null: null, undefined, NaN, "".

  • [config] Object optional

    Optional configuration values, same as for Y.Date.format.

    • [prefix] String optional

      String to be removed from the start, like a currency designator "$"

    • [decimalPlaces] Number optional

      Ignored, it is accepted only for compatibility with Y.Date.format.

    • [decimalSeparator] String optional

      Decimal separator.

    • [thousandsSeparator] String optional

      Thousands separator.

    • [suffix] String optional

      String to be removed from the end of the number, like " items".

Returns:

Number:

A number, or null.