1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-Number'>/**
2 </span> * @class Ext.Number
4 * A collection of useful static methods to deal with numbers
10 var isToFixedBroken = (0.9).toFixed() !== '1';
13 <span id='Ext-Number-method-constrain'> /**
14 </span> * Checks whether or not the current number is within a desired range. If the number is already within the
15 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
16 * exceeded. Note that this method returns the constrained value but does not change the current number.
17 * @param {Number} number The number to check
18 * @param {Number} min The minimum number in the range
19 * @param {Number} max The maximum number in the range
20 * @return {Number} The constrained value if outside the range, otherwise the current value
22 constrain: function(number, min, max) {
23 number = parseFloat(number);
26 number = Math.max(number, min);
29 number = Math.min(number, max);
34 <span id='Ext-Number-method-toFixed'> /**
35 </span> * Formats a number using fixed-point notation
36 * @param {Number} value The number to format
37 * @param {Number} precision The number of digits to show after the decimal point
39 toFixed: function(value, precision) {
40 if (isToFixedBroken) {
41 precision = precision || 0;
42 var pow = Math.pow(10, precision);
43 return (Math.round(value * pow) / pow).toFixed(precision);
46 return value.toFixed(precision);
49 <span id='Ext-Number-method-from'> /**
50 </span> * Validate that a value is numeric and convert it to a number if necessary. Returns the specified default value if
53 Ext.Number.from('1.23', 1); // returns 1.23
54 Ext.Number.from('abc', 1); // returns 1
56 * @param {Mixed} value
57 * @param {Number} defaultValue The value to return if the original value is non-numeric
58 * @return {Number} value, if numeric, defaultValue otherwise
60 from: function(value, defaultValue) {
61 if (isFinite(value)) {
62 value = parseFloat(value);
65 return !isNaN(value) ? value : defaultValue;
71 <span id='Ext-method-num'>/**
72 </span> * This method is deprecated, please use {@link Ext.Number#from Ext.Number.from} instead
74 * @deprecated 4.0.0 Replaced by Ext.Number.from
78 Ext.num = function() {
79 return Ext.Number.from.apply(this, arguments);
80 };</pre></pre></body></html>