BIRT Exchange Forum: Default number formatting - BIRT Exchange Forum

Jump to content


 

BIRT Poll: Have you ever done any development work on mobile?

Yes - lotsYes - someNo - but plan toNo time or interestWhat is mobile?
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Default number formatting Internatinoal number formatting issue Rate Topic: -----

#1 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 19 June 2012 - 03:16 AM

Hello,

I'm using BIRT 2.5.2,
I have a strange issue related to the default number formatting.
The system decimal separator is not used when the report Data value is of type decimal and float.
same issue when using Dynamic Text instead of Data box.

Only when a Data field is used and the type is set to String, the correct decimal separator is used!

My PC is set to use German format so I'm expecting to have a decimal values separated by commas instead of dots.

Ex. Expected : 0,33
Dynamic text: Math.round(1/3*100)/100 => 0.33 -WRONG
Data field: Math.round(10*5/3*100)/100 Data Type: Decimalor Float => 0.33 -WRONG

Data field Math.round(10*5/3*100)/100 Data Type: String => 0,33 - OK



Any help is appreciated.
Thanks in advance
0

#2 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 19 June 2012 - 03:45 AM

I have also tried to "force" a text/string values in the Dynamic Text field like this:

(Math.round(1/3*100)/100).toString()

and

""+(Math.round(1/3*100)/100)

but the problem is still the same, the output is 0.33 instead of 0,33
0

#3 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 13092
  • Joined: 16-May 08


Posted 19 June 2012 - 10:37 AM

If I set the default locale of my Eclipse to German (in the preferences) and use the same expression as you're using, I get the correct format only when using Float or Decimal. Not when using String or a Dynamic Text Box.
Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
1

#4 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 19 June 2012 - 12:55 PM

View Postmwilliams, on 19 June 2012 - 11:37 AM, said:

If I set the default locale of my Eclipse to German (in the preferences) and use the same expression as you're using, I get the correct format only when using Float or Decimal. Not when using String or a Dynamic Text Box.


Hi Michael,

Thanks for your quick answer, I have not changed the locale in the BIRT Report Designer (2.5.2) but checking that under Preferences I have remarked that the selected local was dansk(Danmark), as previously I have changed the PC local to Denmark, and the only problem is that the selected local (detected automatically by the RCP Designer) started with lowercase d - using this as previously mentioned only the Data field of type String was correctly formatted.
Changing that to uppercase D - Dansk(Danmark) both Data fields of type String and Decimal are correctly formatted.

BUG: Auto detected locals in BIRT RCP Designer 2.5.2 for Denmark system format, start with lowercase letter and the decimal number formatting is wrong, only the Data fields of type String are correctly formatted.

How to reproduce : Set PC Format (Under Regions and Languages) to Danish (Denmark) then Open/Restart BIRT RCP Designer -> Window -> Preferences -> Select Report Design then Preview
Empty the field "Choose your locale" then select Apply and OK, reopen the Preferences window will show the default locale starting with lowercase letter like this : dansk (Danmark)

Is there a simple way to set the correct decimal number formatting for a Dynamic Text Box or we must use a Data fields instead?

Thanks in advance
0

#5 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 13092
  • Joined: 16-May 08


Posted 19 June 2012 - 02:08 PM

This will work in a dynamic text to get German.

importPackage (Packages.java.text);
importPackage (Packages.java.util);
temp = 0.33;
nf = NumberFormat.getInstance(Locale.GERMAN);
nf.format(temp);


Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
1

#6 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 19 June 2012 - 09:38 PM

View Postmwilliams, on 19 June 2012 - 03:08 PM, said:

This will work in a dynamic text to get German.

importPackage (Packages.java.text);
importPackage (Packages.java.util);
temp = 0.33;
nf = NumberFormat.getInstance(Locale.GERMAN);
nf.format(temp);



Thanks a lot it works well, just one more question related to this, is it necessarily to use this code for using the default number formatting for Dynamic Text:

importPackage (Packages.java.text);
importPackage (Packages.java.util);
temp = 0.33;
nf = NumberFormat.getInstance();
nf.format(temp);



or it has been fixed in the recent BIRT versions ( > 2.5.2) so the dynamic text is automatically formatted with the default locale?

Thanks in advance
0

#7 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 20 June 2012 - 05:11 AM

View Postdaniel_v, on 19 June 2012 - 10:38 PM, said:

Thanks a lot it works well, just one more question related to this, is it necessarily to use this code for using the default number formatting for Dynamic Text:

importPackage (Packages.java.text);
importPackage (Packages.java.util);
temp = 0.33;
nf = NumberFormat.getInstance();
nf.format(temp);



or it has been fixed in the recent BIRT versions ( > 2.5.2) so the dynamic text is automatically formatted with the default locale?

Thanks in advance



HI again,

In the report designer the following code works well :

importPackage (Packages.java.text);
importPackage (Packages.java.util);
temp = 0.33;
nf = NumberFormat.getInstance();
nf.format(temp);



But does not work into my report viewer, I have specified the __locale parameter as __locale=da_DK

It seams that the default Locale used by the report viewer is not that specified by the __locale parameter?

Thanks in advance

PS: I have remarked that there are lot of SPAM replies to this topic :S
0

#8 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 13092
  • Joined: 16-May 08


Posted 20 June 2012 - 05:49 AM

Does it work if you put the Locale into the format? i.e. nf = NumberFormat.getInstance(new Locale("da","DK"));
Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
1

#9 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 20 June 2012 - 09:07 PM

View Postmwilliams, on 20 June 2012 - 06:49 AM, said:

Does it work if you put the Locale into the format? i.e. nf = NumberFormat.getInstance(new Locale("da","DK"));


Hi Michael,

Thanks again for your answer, YES, setting the Locale into the format works well
i.e
i.e. nf = NumberFormat.getInstance(new Locale("da","DK"));


But this solution does not solve my problem as I need to have dynamic locale in the reports - specified in the report URL (... __locale=<user_locale>)

Example:
http://localhost:8900/WebViewerExampel/frameset?_-report=MyReport.rptdesign&__locale=fr_CA


Into the BIRT documentation I have found the following about the _locale parameter :

Quote

Specifies the locale for the specific operation.
Note that this will override the default locale.
Order of precedence is as follows:

__locale parameter.

Locale from client browser.

Locale web.xml setting.

Locale for the application server.


But it seams that is not working like this on my report viewer 2.5.2 :(

Any suggestions are very appreciated!
Thanks in advance
0

#10 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 20 June 2012 - 09:08 PM

View Postmwilliams, on 20 June 2012 - 06:49 AM, said:

Does it work if you put the Locale into the format? i.e. nf = NumberFormat.getInstance(new Locale("da","DK"));


Hi Michael,

Thanks again for your answer, YES, setting the Locale into the format works well
i.e
i.e. nf = NumberFormat.getInstance(new Locale("da","DK"));


But this solution does not solve my problem as I need to have dynamic locale in the reports - specified in the report URL (... __locale=<user_locale>)

Example:
http://localhost:8900/WebViewerExampel/frameset?_-report=MyReport.rptdesign&__locale=fr_CA


Into the BIRT documentation I have found the following about the _locale parameter :

Quote

Specifies the locale for the specific operation.
Note that this will override the default locale.
Order of precedence is as follows:

__locale parameter.

Locale from client browser.

Locale web.xml setting.

Locale for the application server.


But it seams that is not working like this on my report viewer 2.5.2 :(

Any suggestions are very appreciated!
Thanks in advance
0

#11 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 13092
  • Joined: 16-May 08


Posted 20 June 2012 - 09:45 PM

Try this:

importPackage (Packages.java.text);
importPackage (Packages.java.util);
temp = 0.33;
localeCode = reportContext.getLocale();
lang = localeCode.getLanguage();
country = localeCode.getCountry();
nf = NumberFormat.getInstance(new Locale(lang,country));
nf.format(temp);


Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
1

#12 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 20 June 2012 - 10:07 PM

With my latest tests I have found that when I'm using a number formatting without locale (i.e with default locale) then the JVM locale will be used as it's noted into the JAVA doc for the default locale :

Quote

Gets the current value of the default locale for this instance of the Java Virtual Machine.


and that is the reason why the number formatting is wrong in my reports.

All I need is to have a number formatting based on the __locale parameters specified in the report URL,
and it seams that the only way is to use Data boxes with Decimal data type specified?

Note: I'm using BIRT Viewer 2.5.2

Any help is appreciated!
Thanks in advance
0

#13 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 20 June 2012 - 10:08 PM

View Postmwilliams, on 20 June 2012 - 10:45 PM, said:

Try this:

importPackage (Packages.java.text);
importPackage (Packages.java.util);
temp = 0.33;
localeCode = reportContext.getLocale();
lang = localeCode.getLanguage();
country = localeCode.getCountry();
nf = NumberFormat.getInstance(new Locale(lang,country));
nf.format(temp);




Ahh using the report context locale instead of the system locale, I will check it and back to you shortly,
Thanks
0

#14 User is offline   daniel_v Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 17-September 08


Posted 20 June 2012 - 10:15 PM

View Postmwilliams, on 20 June 2012 - 10:45 PM, said:

Try this:

importPackage (Packages.java.text);
importPackage (Packages.java.util);
temp = 0.33;
localeCode = reportContext.getLocale();
lang = localeCode.getLanguage();
country = localeCode.getCountry();
nf = NumberFormat.getInstance(new Locale(lang,country));
nf.format(temp);



This solution works great (the number formatting in now based on the __locale parameter specified in the report URL).

Is this issue fixed in the recent BIRT versions (>2.5.2)?
I think that by default the number formatting should be based on the __locale parameter

Thanks for your help
0

#15 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 13092
  • Joined: 16-May 08


Posted 22 June 2012 - 07:05 AM

I just tried in 3.7.2 and it appears that you can simply do new Number(0.33), in the dynamic text box. Then, when you set the locale parameter to da_DK, in the URL, it changes, correctly, to 0,33. So, this is better, now, it appears.
Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users