-
31 Aug 2011 8:28 AM #1
Euro or other currency value to format
Euro or other currency value to format
Such thing as util.format.usMoney to format the currency the euro or other currency. I was trying to duplicate the function to suit my needs, but I could not do it.
This is the code of the function
I appreciate any help i can offer.Code:usMoney : 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('.'), whole = ps[0], sub = ps[1] ? '.'+ ps[1] : '.00', 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; },
-
9 Aug 2012 3:23 AM #2
I didnt understand
I didnt understand
Hi,
I didnt understand what you need.. Do you want override Ext.util.Format.usMoney function ? And what are your needs ?sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.
-
9 Aug 2012 4:57 AM #3
Yes, i need override usMoney or add others currencys in the same function.
-
9 Aug 2012 11:31 PM #4
Ext.override
Ext.override
Hi,
you can use Ext.override. Please see below code:
Example:Code:Ext.override(Ext.util.Format, { usMoney : function(v, sign, end) { 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('.'), whole = ps[0], sub = ps[1] ? '.'+ ps[1] : '.00', 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); } if(end) { return v + sign; } else { return sign + v; } } })
Code:Ext.util.Format.usMoney('12','TL',true) //returns "12.00TL"sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.
-
3 Sep 2012 7:47 AM #5
I could not do that overrides the method usMoney. Where should I place that code?
The place where I have a js function, then the onReady and then within InitComponent and not work.


Reply With Quote