tidy yp formating
[roojs1] / Roo / util / Format.js
index 5092b2f..249fd70 100644 (file)
@@ -195,9 +195,7 @@ Roo.util.Format = function(){
             // add comma's
             
             if(thousandsDelimiter.length != 0) {
-                while (r.test(whole)) {
-                    whole = whole.replace(r, '$1' + thousandsDelimiter + '$2');
-                }
+                whole = whole.replace(/\B(?=(\d{3})+(?!\d))/g, thousandsDelimiter );
             } 
             
             var sub = ps[1] ?
@@ -247,7 +245,26 @@ Roo.util.Format = function(){
          */
         stripTags : function(v){
             return !v ? v : String(v).replace(this.stripTagsRE, "");
+        },
+        
+        /**
+         * Size in Mb,Gb etc.
+         * @param {Number} value The number to be formated
+         * @param {number} decimals how many decimal places
+         * @return {String} the formated string
+         */
+        size : function(value, decimals)
+        {
+            var sizes = ['b', 'k', 'm', 'g', 't'];
+            if (value == 0) {
+                return 0;
+            }
+            var i = parseInt(Math.floor(Math.log(value) / Math.log(1024)));
+            return Roo.util.Format.number(value/ Math.pow(1024, i) ,decimals)   + sizes[i];
         }
+        
+        
+        
     };
 }();
 Roo.util.Format.defaults = {