-
15 Jan 2009 6:56 PM #21
-
7 Apr 2009 6:45 AM #22
thx to mystix :-)
here are my changes:
- remove space between number and symbol so you can decide by yourself with the symbol parameter if you like to have a space
- add parameter for position of symbol
usage:PHP Code:if (Ext.util.Format) {
if (!Ext.util.Format.CurrencyFactory) {
Ext.util.Format.CurrencyFactory = function(dp, dSeparator, tSeparator, symbol, rightPosition) {
return function(n) {
dp = Math.abs(dp) + 1 ? dp : 2;
dSeparator = dSeparator || ".";
tSeparator = tSeparator || ",";
symbol = symbol || "$";
rightPosition = rightPosition || false;
var m = /(\d+)(?:(\.\d+)|)/.exec(n + ""),
x = m[1].length > 3 ? m[1].length % 3 : 0;
var v = (n < 0? '-' : '') // preserve minus sign
+ (x ? m[1].substr(0, x) + tSeparator : "")
+ m[1].substr(x).replace(/(\d{3})(?=\d)/g, "$1" + tSeparator)
+ (dp? dSeparator + (+m[2] || 0).toFixed(dp).substr(2) : "");
return rightPosition?v+symbol:symbol+v;
};
};
}
}
PHP Code:var eurFormatter = Ext.util.Format.CurrencyFactory(2, ",", ".", "\u20ac", true);
var value = 12345.67;
return eurFormatter(value); //--> 12.345,67€
var usFormatter = Ext.util.Format.CurrencyFactory();
var value = 12345.67;
return usFormatter(value); //--> $12,345.67
-
7 Apr 2009 6:52 AM #23
if you dont like to give the space into the symbol parameter then use this:
usage:PHP Code:if (Ext.util.Format) {
if (!Ext.util.Format.CurrencyFactory) {
Ext.Ext.util.Format.CurrencyFactory = function(hasSpace, dp, dSeparator, tSeparator, symbol, rightPosition) {
return function(n) {
var spaceText = hasSpace?" ":"";
dp = Math.abs(dp) + 1 ? dp : 2;
dSeparator = dSeparator || ".";
tSeparator = tSeparator || ",";
symbol = symbol || "$";
rightPosition = rightPosition || false;
var m = /(\d+)(?:(\.\d+)|)/.exec(n + ""),
x = m[1].length > 3 ? m[1].length % 3 : 0;
var v = (n < 0? '-' : '') // preserve minus sign
+ (x ? m[1].substr(0, x) + tSeparator : "")
+ m[1].substr(x).replace(/(\d{3})(?=\d)/g, "$1" + tSeparator)
+ (dp? dSeparator + (+m[2] || 0).toFixed(dp).substr(2) : "");
return rightPosition?v+spaceText+symbol:symbol+spaceText+v;
};
};
}
}
PHP Code:var eurFormatter = Ext.util.Format.CurrencyFactory(false,2, ",", ".", "\u20ac", true);
var value = 12345.67;
return eurFormatter(value); //--> 12.345,67€
var eurFormatter = Ext.util.Format.CurrencyFactory(true,2, ",", ".", "\u20ac", true);
var value = 12345.67;
return eurFormatter(value); //--> 12.345,67 €
var usFormatter = Ext.util.Format.CurrencyFactory();
var value = 12345.67;
return usFormatter(value); //--> $12,345.67
var usFormatter = Ext.util.Format.CurrencyFactory(true);
var value = 12345.67;
return usFormatter(value); //--> $ 12,345.67
-
2 Aug 2010 2:10 AM #24
Maybe a bit older thread, but it was usefull for me!
Pimped it a bit to use it in an EditorGrid, so that you can type in values with commata, then transform it to Euro value, or if there is no value an - to keep the grid much cleaner to look ad.
Hope it is usefull for some of you..Code:// // EURO // Ext.util.Format.Currency = function(v) { v = Ext.num(String(v).replace(/\,/, '.')); v = (Math.round((v-0)*100))/100; v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v); if (v==0) { v = '-'; return (v); } else { return (v + ' €').replace(/\./, ','); } };
Regards
SosyI prefer an sister in the red-light district, to an brother with internet explorer..
-
2 Aug 2010 2:40 AM #25
Thank you for sharing.
Jozef Sakalos, aka Saki
A lot of valuable info at:
Saki's Extensions and Plugins
Saki's Extensions and Plugins Docs
Saki's Examples, Latest: Grid in Card Layout
Saki's Blog, Featured: Writing a Big Application in Ext, Latest: Grid MultiSearch Plugin Video
-
6 Oct 2010 10:52 PM #26
Hi All,
I am beginner in ExtJS so bear my newbie Questions.
Where do I place the custom currency render-er? In the beginning of the code? Any examples will be higher appreciated.
Eg. "replaceParameter.push({oldStr:"{{totalPaidAmount}}", newStr:Ext.util.Format.usMoney(totalPaidAmount)}); "
If I want to put "gbMoney" how do I do it .. in a very layman terms.
Thank you
Kind Regards
Yassyboy
-
7 Oct 2010 3:27 AM #27Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Code:Ext.util.Format.gbMoney = function(value){ return ... };
-
16 Dec 2010 1:20 AM #28
If you want to emphasize on usMoney, here is an example for Euro :
Code:Euro = function(v) { v = Ext.util.Format.usMoney(v); if (v=='$0.00') return '-'; else return v.replace(/\$/, '').replace(/\,/g, ' ').replace(/\./, ',')+' &euro'; };
-
30 Oct 2011 11:24 PM #29
this is for other currency's format
this is for other currency's format
I've made some modification from original form (usMoney) function
this is for japan currency (yen = ¥)
here it's for other currency's symbols :Code:Ext.util.Format.jpyMoney = function(v) { // override Ext.util.usMoney v = Ext.num(v, 0); // ensure v is a valid numeric value, otherwise use 0 as a base (fixes $NaN.00 appearing in summaryRow when no records exist) v = (Math.round((v - 0) * 100)) / 100; v = (v == Math.floor(v)) ? v + "" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v); v = String(v); var ps = v.split('.'); var whole = ps[0]; var sub = ps[1] ? '.'+ ps[1] : ''; var r = /(\d+)(\d{3})/; while (r.test(whole)) { whole = whole.replace(r, '$1' + ',' + '$2'); } v = whole + sub; if (v.charAt(0) == '-') { return '-¥ ' + v.substr(1); } return "¥ " + v; }
http://www.hypergurl.com/asciisymbols.htmlLast edited by citstudio; 30 Oct 2011 at 11:28 PM. Reason: adding phrase
-
10 Sep 2012 5:25 AM #30
PHP Code:Ext.util.Format.euroCurrency = function(v){
return Ext.util.Format.currency(v, '€', 2);
};
and in your app launch
launch: function() {
if (Ext.util.Format) {
Ext.apply(Ext.util.Format, {
thousandSeparator : '.',
decimalSeparator : ','
});
};
}


Reply With Quote