X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2Futil%2FFormat.js;fp=Roo%2Futil%2FFormat.js;h=03fbabe9ff1888e1a676c3e72fb8ac5a142c07b6;hb=9f8d87bc51eb15080637e5fb5ef63913529df854;hp=8c900261e623481f3d68adb982b96b8f94f61630;hpb=c3fae677247c171d616820f63a06609c27abacb3;p=roojs1 diff --git a/Roo/util/Format.js b/Roo/util/Format.js index 8c900261e6..03fbabe9ff 100644 --- a/Roo/util/Format.js +++ b/Roo/util/Format.js @@ -245,7 +245,25 @@ 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 (v == 0) { + return 0; + } + var i = parseInt(Math.floor(Math.log(v) / Math.log(1024))); + return this.number(v / Math.pow(1024, i) ,decimals) + ' ' + sizes[i]; } + + + }; }(); Roo.util.Format.defaults = {