/** * @class Ext.util.Numbers * @singleton */ Ext.util.Numbers = { // detect toFixed implementation bug in IE toFixedBroken: (0.9).toFixed() != 1, /** * Checks whether or not the current number is within a desired range. If the number is already within the * range it is returned, otherwise the min or max value is returned depending on which side of the range is * exceeded. Note that this method returns the constrained value but does not change the current number. * @param {Number} number The number to check * @param {Number} min The minimum number in the range * @param {Number} max The maximum number in the range * @return {Number} The constrained value if outside the range, otherwise the current value */ constrain : function(number, min, max) { number = parseFloat(number); if (!isNaN(min)) { number = Math.max(number, min); } if (!isNaN(max)) { number = Math.min(number, max); } return number; }, /** * Formats a number using fixed-point notation * @param {Number} value The number to format * @param {Number} precision The number of digits to show after the decimal point */ toFixed : function(value, precision) { if(Ext.util.Numbers.toFixedBroken) { precision = precision || 0; var pow = Math.pow(10, precision); return Math.round(value * pow) / pow; } return value.toFixed(precision); } };