datatype-number.js revision 9a71d55c13f410382a33268d214e9110d0567a78
/**
* The DataType utility provides a set of utility functions to operate on native
* JavaScript data types.
*
* @module datatype
*/
/**
* Number submodule.
*
* @class DataType.Number
* @static
*/
Number = {
/**
* Converts data to type Number.
*
* @method parse
* @param data {String | Number | Boolean} Data to convert. Note, the following
* values return as null: null, undefined, NaN, "".
* @return {Number} A number, or null.
* @static
*/
return null;
}
//Convert to number
// Validate
return number;
}
else {
return null;
}
},
/**
* Takes a Number and formats to string for display to user.
*
* @method format
* @param data {Number} Number.
* @param 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.</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>
* @return {String} Formatted number for display. Note, the following values
* return as "": null, undefined, NaN, "".
*/
return "";
}
data *= 1;
}
var dotIndex;
// Manage decimals
// Round to the correct decimal place
if(decPlaces > 0) {
// Add the decimal separator
if(dotIndex < 0) {
}
// Replace the "."
else if(decSep !== "."){
}
// Add missing zeros
output += "0";
}
}
}
// Add the thousands separator
if(config.thousandsSeparator) {
var count = -1;
for (var i=dotIndex; i>0; i--) {
count++;
}
}
}
// Prepend prefix
// Append suffix
return output;
}
// Still not a Number, just return unaltered
else {
return data;
}
}
};
Y.namespace("DataType").Number = Number;