-
4 Oct 2007 11:50 AM #11
Include in locale
Include in locale
I totally agree. But also should currency translations come as a part of the locale translation file. Just as important as having dates translated to a regional format is having the currency format translated.
I guess Violinistas function would cover most currency formats.. It lets you choose your own currency notation, thousand separator and decimal separator. Maybe should you even be able to choose wether the currency notation should come before or after the value...?
-
21 Nov 2007 5:31 AM #12
frMoney (euro)
frMoney (euro)
Here's my 2 cents for French formatting, you can include this in the locale file ext-lang-fr.js
Code:if (Ext.util.Format) { Ext.util.Format.frMoney = function(v){ v = (Math.round((v-0)*100))/100; v = (v == Math.floor(v)) ? v + ".00" : ((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] : ',00'; 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 + " €"; }; }Guillaume
ExtJS: 3.3.0 / ext-base.js - Windows XP SP3 - Firefox 3.6.12
-
25 Feb 2008 5:54 AM #13
[QUOTE=brian.moeskau;27131]There are no plans for including additional formats directly in Ext as the complete list would be quite long and most people would never need most of them. You can easily provide your own by adding your own function anywhere after Ext.util.Format is included:
[CODE]
Ext.util.Format.gbMoney = function(v){
v = (Math.round((v-0)*100))/100;
v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
return "fGwNetworks.nl Rich Internet Application development
-
31 Aug 2008 8:08 PM #14
[QUOTE=mystix;58646]just for fun (don't hit me
), why not create a factory
[code][s]
Ext.util.Format.CurrencyFactory = function(c, d, t, s) {
return function(n) {
var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".",
/(d+)(?
.d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0;
return ((x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(d{3})(?=d)/g,
"$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : ""))+" "+s;
}
}
var euroFormatter = Ext.util.Format.CurrencyFactory(2, ",", ".", "
-
31 Aug 2008 8:49 PM #15
[QUOTE=siyuan;216991][code]
Ext.util.Format.CurrencyFactory = function(c, d, t, s) {
return function(n) {
var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".",
/(\d+)(?
\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0;
return ((x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(d{3})(?=d)/g,
"$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : ""))+" "+s;
}
}
var euroFormatter = Ext.util.Format.CurrencyFactory(2, ",", ".", "
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
31 Aug 2008 9:54 PM #16
[QUOTE=siyuan;216991][code]
Ext.util.Format.CurrencyFactory = function(c, d, t, s) {
return function(n) {
var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".",
/(\d+)(?
\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0;
return ((x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(d{3})(?=d)/g,
"$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : ""))+" "+s;
}
}
var euroFormatter = Ext.util.Format.CurrencyFactory(2, ",", ".", "
-
12 Jan 2009 7:52 PM #17
Works great.. except if it's a negative number it drops the - signCode:Ext.util.Format.CurrencyFactory = function(c, d, t, s) { return function(n) { var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".", /(\d+)(?:(\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0; return ((x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : ""))+" "+s; } }
-
15 Jan 2009 6:01 PM #18
- the decimal and thousand separators are reversed
- to keep the minus sign, simply store it somewhere if it exists
- the parameter names are confusing
you might also want to check out @condor's number formatter atCode:Ext.util.Format.CurrencyFactory = function(dp, dSeparator, tSeparator, symbol) { return function(n) { dp = Math.abs(dp) + 1 ? dp : 2; dSeparator = dSeparator || "."; tSeparator = tSeparator || ","; var m = /(\d+)(?:(\.\d+)|)/.exec(n + ""), x = m[1].length > 3 ? m[1].length % 3 : 0; return (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) : "") + " " + symbol; }; };
http://extjs.com/forum/showthread.php?t=48600Last edited by mystix; 15 Jan 2009 at 6:33 PM. Reason: update
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
15 Jan 2009 6:14 PM #19
-
15 Jan 2009 6:32 PM #20
sorry, forgot to fix the reversed decimal / thousand separators in the code.
also fixed some spelling errors (yes i'm a perfectionist...)
check the previous post again.
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )





Reply With Quote