PDA

View Full Version : [CLOSED] [#494] Euroformat



CarWise
May 23, 2014, 10:04 AM
Hi,

Using Euroformat in my renderer it seems that te format for my country is wrong. It's displayed after the amount, but in several european countries we show the Euro sign before the amount :) ..

(http://en.wikipedia.org/wiki/Linguistic_issues_concerning_the_euro)

Is there a way to change this in code ? Using LCID in the page directive didn't change the outcome


Martin

Daniil
May 23, 2014, 10:23 AM
Hi Martin,

You can override this:

Ext.util.Format.euroMoney = function (v) {
v = String(v).replace(/[^0-9.\-]/g, "");
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');
}

return whole + sub + " €";
};

CarWise
May 23, 2014, 10:34 AM
Will do... thanks !

Is there a chance you can show the right format depending on the culture in the future ? Or must this be submitted to Sencha ?

Martin

Daniil
May 23, 2014, 1:34 PM
Could you provide us with an override to some specific locale. Then I could add it to SVN.

CarWise
May 26, 2014, 10:34 AM
Could you provide us with an override to some specific locale. Then I could add it to SVN.



Ext.util.Format.euroMoney = function (v) {
v = String(v).replace(/[^0-9.\-]/g, "");
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');
}


return "€ " + whole + sub;
};


Netherlands, Austria, UK, Ireland, Malta, Cyprus, Latvia, Turkey, Scotland, Wales, Belgium :)

Daniil
May 26, 2014, 1:03 PM
Ok, thanks. Created an Issue for that.
https://github.com/extnet/Ext.NET/issues/494

So, the only change is a euro sign position. I think it is worth to introduce a new boolean setting, like "euroPrefix".

Ext.util.Format.euroMoney


Ext.util.Format.euroMoney = function (v) {
v = String(v).replace(/[^0-9.\-]/g, "");
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 (!Ext.util.Format.euroPrefix) {
v = v + " €";
} else {
v = "€ " +v;
}

return v;
};

The change has been committed to SVN trunk in the revision #5851.

Then, if a euro sign should be prefixed, you can set up just

Ext.util.Format.euroPrefix = true;


Netherlands, Austria, UK, Ireland, Malta, Cyprus, Latvia, Turkey, Scotland, Wales, Belgium :)

Just a half of these locales are supported by ExtJS. So, I would leave it all under a developer's responsibility. Please set

Ext.util.Format.euroPrefix = true;
if you need a euro sign to be prefixed.

CarWise
May 26, 2014, 1:05 PM
Yes, the only difference is the position. But I'm sure that my clients will complain about it haha...

Thank you for your cooperation :)

Martin

CarWise
May 26, 2014, 1:17 PM
Looking closer into the wikipage it seems that in the UK (Scotland, Wales), Ireland and Malta there is no space between the sign and the amount. I'm not sure it's worth to look into that also..

Martin

Daniil
May 26, 2014, 5:50 PM
I am not sure too:) What would you say?

CarWise
May 27, 2014, 7:54 AM
I am not sure too:) What would you say?

Well...it's no issue for me, but probably an issue for UK users of EXT.NET ... so you decide haha..

Daniil
May 28, 2014, 5:47 AM
Ok, I think if they complain, we will review that again.