-
30 Apr 2007 5:38 AM #1
Other currency formats other than usMoney ?
Other currency formats other than usMoney ?
Are there plans to support other currency formats (e.g.
-
1 May 2007 2:43 AM #2
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 "
-
1 May 2007 2:47 AM #3
Cheers Brian. Your way is much slicker than a custom renderer, I'm sure many will find this fragment useful.
-
1 May 2007 8:47 AM #4
Almost the same, just replacing the decimal separator:
[code]
// plug German currency renderer into formatter
Ext.util.Format.deMoney = 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 (v + 'Kind regards,
WillyDee
Problems worthy of attack, prove their worth by hitting back.
-
2 May 2007 3:33 AM #5
Thanks Brian.
I also need this.
-
29 Aug 2007 8:14 AM #6
After a while, in need for some more advanced currency formatting with thousand separating, I found complete solution there and adopted it to use with extJs; I use it heavily in my datagrids, as a renderer. The customizable params are intentionally put in function body, for using it in renderer,without touch.
Here it is:
[php]
/**
* Improved currency formatter with thousands separator
* Configurable options:
* c - number of digits after decimal separator
* d - decimal separator
* t - thousand separator
* s - currency symbol
* @param {Object} number/string which have to be formatted!
* @return {string} formatted number
*/
Ext.util.Format.Currency = function(n) {
var c=2, d=",", t=".", s=""It is better to be young, pretty and rich instead old, ugly and poor."
(c) Alan Ford.
-
29 Aug 2007 8:20 AM #7
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, ",", ".", "€");
var dollarFormatter = Ext.util.Format.CurrencyFactory(2, ",", ".", "$");
var yenFormatter = 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 )
-
29 Aug 2007 8:27 AM #8
Thanks! Much useful, I am heavily using factory pattern in my backend code, but forgot about it in Js... But improving every day!

HINT: "$" and some other symbols must reside BEFORE currency number, thing 'bout it! Maybe some switch ... case statement before value returnig, to determine whether symbol resides before or after currency amount.
10X!
[EDIT 1]: Not sure how to resolve your bugs really. Xaxaxa"It is better to be young, pretty and rich instead old, ugly and poor."
(c) Alan Ford.
-
15 Sep 2007 7:21 AM #9
I a reply to willydee's code I wrote a little change.
As it hapens the € sign does not work in some occasions and I replaced it with €
My changed code:Willydee's code :
Code:// plug German currency renderer into formatter Ext.util.Format.deMoney = 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 (v + ' €').replace(/\./, ','); };
Code:// plug European currency renderer into formatter Ext.util.Format.Currency = 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 ('€' + v).replace(/\./, ','); };
-
16 Sep 2007 4:52 AM #10
Having Euro (and Yen and other major currencies) in the Ext distro is a must, IMHO.
I'm +1 so it doesn't feel so American only
I'm part of the Ext Community
Maintaining: Translations and some Examples
Developing on: ExtJS Python Builder / Gozerbot
Places: Ido.nl.eu.org / My ExtSamples / Trbs on Wiki / IRC


Reply With Quote