From 9f8d87bc51eb15080637e5fb5ef63913529df854 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Wed, 9 Jun 2021 11:02:16 +0800 Subject: [PATCH] add size formating to util format --- Roo/util/Format.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 = { -- 2.39.2