4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-Number'>/**
19 </span> * @class Ext.Number
21 * A collection of useful static methods to deal with numbers
27 var isToFixedBroken = (0.9).toFixed() !== '1';
30 <span id='Ext-Number-method-constrain'> /**
31 </span> * Checks whether or not the current number is within a desired range. If the number is already within the
32 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
33 * exceeded. Note that this method returns the constrained value but does not change the current number.
34 * @param {Number} number The number to check
35 * @param {Number} min The minimum number in the range
36 * @param {Number} max The maximum number in the range
37 * @return {Number} The constrained value if outside the range, otherwise the current value
39 constrain: function(number, min, max) {
40 number = parseFloat(number);
43 number = Math.max(number, min);
46 number = Math.min(number, max);
51 <span id='Ext-Number-method-toFixed'> /**
52 </span> * Formats a number using fixed-point notation
53 * @param {Number} value The number to format
54 * @param {Number} precision The number of digits to show after the decimal point
56 toFixed: function(value, precision) {
57 if (isToFixedBroken) {
58 precision = precision || 0;
59 var pow = Math.pow(10, precision);
60 return (Math.round(value * pow) / pow).toFixed(precision);
63 return value.toFixed(precision);
66 <span id='Ext-Number-method-from'> /**
67 </span> * Validate that a value is numeric and convert it to a number if necessary. Returns the specified default value if
70 Ext.Number.from('1.23', 1); // returns 1.23
71 Ext.Number.from('abc', 1); // returns 1
73 * @param {Mixed} value
74 * @param {Number} defaultValue The value to return if the original value is non-numeric
75 * @return {Number} value, if numeric, defaultValue otherwise
77 from: function(value, defaultValue) {
78 if (isFinite(value)) {
79 value = parseFloat(value);
82 return !isNaN(value) ? value : defaultValue;
88 <span id='Ext-method-num'>/**
89 </span> * This method is deprecated, please use {@link Ext.Number#from Ext.Number.from} instead
91 * @deprecated 4.0.0 Replaced by Ext.Number.from
95 Ext.num = function() {
96 return Ext.Number.from.apply(this, arguments);