* eventually this should probably emulate php's number_format
* @param {Number/String} value The numeric value to format
* @param {Number} decimals number of decimal places
+ * @param {String} delimiter for thousands (default comma)
* @return {String} The formatted currency string
*/
- number : function(v,decimals)
+ number : function(v, decimals, thousandsDelimiter)
{
// multiply and round.
decimals = typeof(decimals) == 'undefined' ? 2 : decimals;
+ thousandsDelimiter = typeof(thousandsDelimiter) == 'undefined' ? ',' : thousandsDelimiter;
+
var mul = Math.pow(10, decimals);
var zero = String(mul).substring(1);
v = (Math.round((v-0)*mul))/mul;
var ps = v.split('.');
var whole = ps[0];
-
var r = /(\d+)(\d{3})/;
// add comma's
- while (r.test(whole)) {
- whole = whole.replace(r, '$1' + ',' + '$2');
- }
+ if(thousandsDelimiter.length != 0) {
+ whole = whole.replace(/\B(?=(\d{3})+(?!\d))/g, thousandsDelimiter );
+ }
var sub = ps[1] ?
// has decimals..
*/
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 = {