Alien-Web-ExtJS-V3

 view release on metacpan or  search on metacpan

share/docs/source/Format.html  view on Meta::CPAN

            } else if (size < 1048576) {
                return (Math.round(((size*10) / 1024))/10) + " KB";
            } else {
                return (Math.round(((size*10) / 1048576))/10) + " MB";
            }
        },

<span id='Ext-util-Format-method-math'>        /**
</span>         * It does simple math for use in a template, for example:&lt;pre&gt;&lt;code&gt;
         * var tpl = new Ext.Template('{value} * 10 = {value:math(&quot;* 10&quot;)}');
         * &lt;/code&gt;&lt;/pre&gt;
         * @return {Function} A function that operates on the passed value.
         */
        math : function(){
            var fns = {};
            
            return function(v, a){
                if (!fns[a]) {
                    fns[a] = new Function('v', 'return v ' + a + ';');
                }
                return fns[a](v);
            };
        }(),

<span id='Ext-util-Format-method-round'>        /**
</span>         * Rounds the passed number to the required decimal precision.
         * @param {Number/String} value The numeric value to round.
         * @param {Number} precision The number of decimal places to which to round the first parameter's value.
         * @return {Number} The rounded value.
         */
        round : function(value, precision) {
            var result = Number(value);
            if (typeof precision == 'number') {
                precision = Math.pow(10, precision);
                result = Math.round(value * precision) / precision;
            }
            return result;
        },

<span id='Ext-util-Format-method-number'>        /**
</span>         * Formats the number according to the format string.
         * &lt;div style=&quot;margin-left:40px&quot;&gt;examples (123456.789):
         * &lt;div style=&quot;margin-left:10px&quot;&gt;
         * 0 - (123456) show only digits, no precision&lt;br&gt;
         * 0.00 - (123456.78) show only digits, 2 precision&lt;br&gt;
         * 0.0000 - (123456.7890) show only digits, 4 precision&lt;br&gt;
         * 0,000 - (123,456) show comma and digits, no precision&lt;br&gt;
         * 0,000.00 - (123,456.78) show comma and digits, 2 precision&lt;br&gt;
         * 0,0.00 - (123,456.78) shortcut method, show comma and digits, 2 precision&lt;br&gt;
         * To reverse the grouping (,) and decimal (.) for international numbers, add /i to the end.
         * For example: 0.000,00/i
         * &lt;/div&gt;&lt;/div&gt;
         * @param {Number} v The number to format.
         * @param {String} format The way you would like to format this text.
         * @return {String} The formatted number.
         */
        number: function(v, format) {
            if (!format) {
                return v;
            }
            v = Ext.num(v, NaN);
            if (isNaN(v)) {
                return '';
            }
            var comma = ',',
                dec   = '.',
                i18n  = false,
                neg   = v &lt; 0;

            v = Math.abs(v);
            if (format.substr(format.length - 2) == '/i') {
                format = format.substr(0, format.length - 2);
                i18n   = true;
                comma  = '.';
                dec    = ',';
            }

            var hasComma = format.indexOf(comma) != -1,
                psplit   = (i18n ? format.replace(/[^\d\,]/g, '') : format.replace(/[^\d\.]/g, '')).split(dec);

            if (1 &lt; psplit.length) {
                v = v.toFixed(psplit[1].length);
            } else if(2 &lt; psplit.length) {
                throw ('NumberFormatException: invalid format, formats should have no more than 1 period: ' + format);
            } else {
                v = v.toFixed(0);
            }

            var fnum = v.toString();

            psplit = fnum.split('.');

            if (hasComma) {
                var cnum = psplit[0], 
                    parr = [], 
                    j    = cnum.length, 
                    m    = Math.floor(j / 3),
                    n    = cnum.length % 3 || 3,
                    i;

                for (i = 0; i &lt; j; i += n) {
                    if (i != 0) {
                        n = 3;
                    }
                    
                    parr[parr.length] = cnum.substr(i, n);
                    m -= 1;
                }
                fnum = parr.join(comma);
                if (psplit[1]) {
                    fnum += dec + psplit[1];
                }
            } else {
                if (psplit[1]) {
                    fnum = psplit[0] + dec + psplit[1];
                }
            }

            return (neg ? '-' : '') + format.replace(/[\d,?\.?]+/, fnum);
        },

<span id='Ext-util-Format-method-numberRenderer'>        /**



( run in 0.503 second using v1.01-cache-2.11-cpan-787462296c9 )