Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / Number3.html
diff --git a/docs/source/Number3.html b/docs/source/Number3.html
new file mode 100644 (file)
index 0000000..cd9a4fa
--- /dev/null
@@ -0,0 +1,80 @@
+<!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'>/**
+</span> * @class Ext.Number
+ *
+ * A collection of useful static methods to deal with numbers
+ * @singleton
+ */
+
+(function() {
+
+var isToFixedBroken = (0.9).toFixed() !== '1';
+
+Ext.Number = {
+<span id='Ext-Number-method-constrain'>    /**
+</span>     * 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;
+    },
+
+<span id='Ext-Number-method-toFixed'>    /**
+</span>     * 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 (isToFixedBroken) {
+            precision = precision || 0;
+            var pow = Math.pow(10, precision);
+            return (Math.round(value * pow) / pow).toFixed(precision);
+        }
+
+        return value.toFixed(precision);
+    },
+
+<span id='Ext-Number-method-from'>    /**
+</span>     * Validate that a value is numeric and convert it to a number if necessary. Returns the specified default value if
+     * it is not.
+
+Ext.Number.from('1.23', 1); // returns 1.23
+Ext.Number.from('abc', 1); // returns 1
+
+     * @param {Mixed} value
+     * @param {Number} defaultValue The value to return if the original value is non-numeric
+     * @return {Number} value, if numeric, defaultValue otherwise
+     */
+    from: function(value, defaultValue) {
+        if (isFinite(value)) {
+            value = parseFloat(value);
+        }
+
+        return !isNaN(value) ? value : defaultValue;
+    }
+};
+
+})();
+
+<span id='Ext-method-num'>/**
+</span> * This method is deprecated, please use {@link Ext.Number#from Ext.Number.from} instead
+ *
+ * @deprecated 4.0.0 Replaced by Ext.Number.from
+ * @member Ext
+ * @method num
+ */
+Ext.num = function() {
+    return Ext.Number.from.apply(this, arguments);
+};</pre></pre></body></html>
\ No newline at end of file