PDA

View Full Version : [FIXED] Ext.util.Format.number /i flag does not work as documented



cdshearer
29 Oct 2013, 12:56 PM
Ext version tested:

Ext 4.2.1
Browser versions tested against:

Chrome 30.0.1599.101 m
DOCTYPE tested against:

Strict
Description:

The internationalization formatting option (/i) as described in the documentation for Ext.util.Format.number does not work. (I have checked the source code - it is tested for and a flag is set but it has no further effect.)
Steps to reproduce the problem:

I have created a fiddle to reproduce the problem. https://fiddle.sencha.com/#fiddle/18u
The result that was expected:


I would expect the format with the /i option to be output as 1.234.567,89
The result that occurs instead:


The output is 1,234,567.89 which is identical to the US/UK output.

evant
29 Oct 2013, 1:07 PM
The docs could probably use some clarification, the /i format also depends on the thousand/decimalSeparator specified on Ext.util.Format:



Ext.application({
name: 'Fiddle',

launch: function() {

var source = 1234567.89;

Ext.util.Format.thousandSeparator = '.';
Ext.util.Format.decimalSeparator = ',';

Ext.getBody().createChild({
html: Ext.util.Format.number(source, '0,000.00/i')
});
}
});


Having said that, I've noticed another issue where it's adding extra trailing 0's when using Euro style separators, so I'll log an issue for that.

Thanks for the post.

cdshearer
29 Oct 2013, 1:42 PM
Interesting - the /i seems to have no effect. So, once Ext.util.Format.thousandSeparator and Ext.util.Format.decimalSeparator values are set then it works fine without the /i flag.

Probably the /i is actually causing the trailing zeros.

evant
29 Oct 2013, 2:01 PM
The purpose of /i is to allow you to specify the format in "locale terms". Without /i, you always have to specify the format assuming thousand = "," & decimal = ".".

Edit:

Sorry, it seems it's a bit too early in the day. In this case the test case is incorrect:



Ext.application({
name: 'Fiddle',

launch: function() {

var source = 1234567.89;

Ext.util.Format.thousandSeparator = '.';
Ext.util.Format.decimalSeparator = ',';

Ext.getBody().createChild({
html: Ext.util.Format.number(source, '0.000,00/i')
});
}
});


If you're using /i, then the format string needs to respect the set thousand/decimal separators. Otherwise, don't use /i and just set the format using "US" style formats and it will substitute the thousand/decimal at the end.

Regardless, the docs could still do with an update.