Number Class
Number provides a set of utility functions to operate against Number objects.
Methods
format
-
data
-
config
Takes a Number and formats to string for display to user.
Parameters:
-
data
NumberNumber.
-
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:
Formatted number for display. Note, the following values return as "": null, undefined, NaN, "".
parse
-
data
-
[config]
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]
Object optionalOptional configuration values, same as for Y.Date.format.
-
[prefix]
String optionalString to be removed from the start, like a currency designator "$"
-
[decimalPlaces]
Number optionalIgnored, it is accepted only for compatibility with Y.Date.format.
-
[decimalSeparator]
String optionalDecimal separator.
-
[thousandsSeparator]
String optionalThousands separator.
-
[suffix]
String optionalString to be removed from the end of the number, like " items".
-
Returns:
A number, or null.