1. #11
    Ext User kayegil.hauan's Avatar
    Join Date
    Aug 2007
    Location
    Trondheim, Norway
    Posts
    8
    Vote Rating
    0
    kayegil.hauan is on a distinguished road

      0  

    Wink Include in locale

    Include in locale


    Quote Originally Posted by trbs View Post
    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 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...?

  2. #12
    Ext User
    Join Date
    Nov 2007
    Location
    France
    Posts
    20
    Vote Rating
    0
    devil1591 is on a distinguished road

      0  

    Default 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

  3. #13
    Ext User
    Join Date
    Feb 2008
    Posts
    145
    Vote Rating
    1
    cabster is on a distinguished road

      0  

    Default


    [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

  4. #14
    Ext User
    Join Date
    Apr 2008
    Posts
    6
    Vote Rating
    0
    siyuan is on a distinguished road

      0  

    Default


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

  5. #15
    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


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

  6. #16
    Ext User
    Join Date
    Apr 2008
    Posts
    6
    Vote Rating
    0
    siyuan is on a distinguished road

      0  

    Default


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

  7. #17
    Sencha User
    Join Date
    Sep 2008
    Posts
    193
    Vote Rating
    0
    fxmisticat is on a distinguished road

      0  

    Default


    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;
      }
    }
    Works great.. except if it's a negative number it drops the - sign

  8. #18
    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


    • the decimal and thousand separators are reversed
    • to keep the minus sign, simply store it somewhere if it exists
    • the parameter names are confusing
    Code:
    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;
        };
    };
    you might also want to check out @condor's number formatter at
    http://extjs.com/forum/showthread.php?t=48600
    Last edited by mystix; 15 Jan 2009 at 6:33 PM. Reason: update

  9. #19
    Sencha User
    Join Date
    Sep 2008
    Posts
    193
    Vote Rating
    0
    fxmisticat is on a distinguished road

      0  

    Default


    very nice thank you!

  10. #20
    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


    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.