* @return {String} The formatted currency string
*/
usMoney : function(v){
- return '$' + this.number(v);
+ return '$' + Roo.util.Format.number(v);
},
/**
* 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] ?
- (decimals ? ('.'+ zero.substring(ps[1].length) + ps[1]) : '') :
+ // has decimals..
+ (decimals ? ('.'+ ps[1] + zero.substring(ps[1].length)) : '') :
+ // does not have decimals
(decimals ? ('.' + zero) : '');
if(!(v instanceof Date)){
v = new Date(Date.parse(v));
}
- return v.dateFormat(format || "m/d/Y");
+ return v.dateFormat(format || Roo.util.Format.defaults.date);
},
/**
return !v ? v : String(v).replace(this.stripTagsRE, "");
}
};
-}();
\ No newline at end of file
+}();
+Roo.util.Format.defaults = {
+ date : 'd/M/Y'
+};
\ No newline at end of file