Number Class
yui3/src/number/js/number-format.js:16
Parent Module: datatype-number
Number provides a set of utility functions to operate against Number objects.
Index
Methods
Methods
_buildParser
-
[prefix]
-
[suffix]
-
[separator]
-
[decimal]
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 optionalPrefix string to be stripped out.
-
[suffix]
String optionalSuffix string to be stripped out.
-
[separator]
String optionalThousands separator to be stripped out.
-
[decimal]
String optionalDecimal separator to be replaced by a dot.
Returns:
Parsing function.
format
-
data
-
config
Takes a Number and formats to string for display to user.
Parameters:
-
data
NumberNumber.
-
config
Object(Optional) Optional configuration values: <dl> <dt>prefix {String}</dd> <dd>String prepended before each number, like a currency designator "$"</dd> <dt>decimalPlaces {Number}</dd> <dd>Number of decimal places to round. Must be a number 0 to 20.</dd> <dt>decimalSeparator {String}</dd> <dd>Decimal separator</dd> <dt>thousandsSeparator {String}</dd> <dd>Thousands separator</dd> <dt>suffix {String}</dd> <dd>String appended after each number, like " items" (note the space)</dd> </dl>
Returns:
Formatted number for display. Note, the following values return as "": null, undefined, NaN, "".
parse
-
data
-
[config] Optional configuration values, same as for [Y.Date.format]
-
[config.prefix]
-
[config.decimalPlaces] Ignored, it is accepted only for compatibility with [Y.Date.format]
-
[config.decimalSeparator]
-
[config.thousandsSeparator]
-
[config.suffix]
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 | BooleanData to convert. The following values return as null: null, undefined, NaN, "".
-
[config] Optional configuration values, same as for [Y.Date.format]
Object optional(#method_format).
-
[config.prefix]
String optionalString to be removed from the start, like a currency designator "$"
-
[config.decimalPlaces] Ignored, it is accepted only for compatibility with [Y.Date.format]
Number optional(#method_format).
-
[config.decimalSeparator]
String optionalDecimal separator.
-
[config.thousandsSeparator]
String optionalThousands separator.
-
[config.suffix]
String optionalString to be removed from the end of the number, like " items".
Returns:
A number, or null.