1. #1
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Default Other currency formats other than usMoney ?

    Other currency formats other than usMoney ?


    Are there plans to support other currency formats (e.g.

  2. #2
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    4
    Vote Rating
    0
    brian.moeskau is an unknown quantity at this point

      0  

    Default


    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 "

  3. #3
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Thumbs up


    Cheers Brian. Your way is much slicker than a custom renderer, I'm sure many will find this fragment useful.

  4. #4
    Sencha Premium Member
    Join Date
    Mar 2007
    Location
    Iloilo, Philippines
    Posts
    149
    Vote Rating
    1
    willydee is on a distinguished road

      0  

    Default


    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.

  5. #5
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,563
    Vote Rating
    384
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Thanks Brian.

    I also need this.

  6. #6
    Ext User violinista's Avatar
    Join Date
    Apr 2007
    Location
    Serbia
    Posts
    293
    Vote Rating
    0
    violinista is on a distinguished road

      0  

    Default


    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.

  7. #7
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default


    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, ",", ".", "

  8. #8
    Ext User violinista's Avatar
    Join Date
    Apr 2007
    Location
    Serbia
    Posts
    293
    Vote Rating
    0
    violinista is on a distinguished road

      0  

    Default


    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.

  9. #9
    Ext User
    Join Date
    Aug 2007
    Location
    Lelystad, The Netherlands
    Posts
    4
    Vote Rating
    0
    ronnyr is on a distinguished road

      0  

    Default


    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 €

    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(/\./, ',');
    };
    My changed code:
    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(/\./, ',');
    };

  10. #10
    Sencha User trbs's Avatar
    Join Date
    Mar 2007
    Posts
    310
    Vote Rating
    0
    trbs is on a distinguished road

      0  

    Default


    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