YUI recommends YUI3.

YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.

This documentation is no longer maintained.

Yahoo! UI Library

DataSource Utility  2.9.0

Yahoo! UI Library > datasource > YAHOO.util.Number
Search:
 
Filters

static Class YAHOO.util.Number

The static Number class provides helper functions to deal with data of type Number.

Properties

Number.format.defaults - static {Object}

Default values for Number.format behavior. Override properties of this object if you want every call to Number.format in your system to use specific presets.

Available keys include:

  • format
  • negativeFormat
  • decimalSeparator
  • decimalPlaces
  • thousandsSeparator
  • prefix/suffix or any other token you want to use in the format templates

Methods

format

String format ( nData , oConfig )
Takes a native JavaScript Number and formats to a string for display.
Parameters:
nData <Number> Number.
oConfig <Object} (Optional) Optional configuration values:
format
String used as a template for formatting positive numbers. {placeholders} in the string are applied from the values in this config object. {number} is used to indicate where the numeric portion of the output goes. For example "{prefix}{number} per item" might yield "$5.25 per item". The only required {placeholder} is {number}.
negativeFormat
Like format, but applied to negative numbers. If set to null, defaults from the configured format, prefixed with -. This is separate from format to support formats like "($12,345.67)".
prefix {String} (deprecated, use format/negativeFormat)
String prepended before each number, like a currency designator "$"
decimalPlaces {Number}
Number of decimal places to round.
decimalSeparator {String}
Decimal separator
thousandsSeparator {String}
Thousands separator
suffix {String> (deprecated, use format/negativeFormat)
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, "".

Number.format._applyFormat

static String Number.format._applyFormat ( tmpl , num , data )
Apply any special formatting to the "d,ddd.dd" string. Takes either the cfg.format or cfg.negativeFormat template and replaces any {placeholders} with either the number or a value from a so-named property of the config object.
Parameters:
tmpl <String> the cfg.format or cfg.numberFormat template string
num <String> the number with separators and decimalPlaces applied
data <Object} the config object, used here to populate {placeholder> s
Returns: String
the number with any decorators added


Copyright © 2011 Yahoo! Inc. All rights reserved.