Where are the resources used by NumberFormat?

Discussion in 'Java' started by Scott Smith, Feb 26, 2007.

  1. Scott Smith

    Scott Smith Guest

    I need to format percentages for 23 different locales, and unfortunately my
    client doesn't use Java. If I recall correctly, in Java I'd use
    NumberFormat.getPercentInstance(locale) [or something like that], and the
    JRE would get the appropriate percent formatting info from a locale-specific
    resource bundle.

    OK, so... where are those resources? I basically need to do something
    similar in a non-Java program, and I want to avoid having to research the
    percent formats for 23 different locales.

    I've done some searching, but haven't been able to find them. Can someone
    point me in the right direction?

    Thanks in advance.

    -Scott
    Scott Smith, Feb 26, 2007
    #1
    1. Advertising

  2. Scott Smith wrote:

    > I need to format percentages for 23 different locales, and unfortunately
    > my client doesn't use Java. If I recall correctly, in Java I'd use
    > NumberFormat.getPercentInstance(locale) [or something like that], and the
    > JRE would get the appropriate percent formatting info from a
    > locale-specific resource bundle.
    >
    > OK, so... where are those resources? I basically need to do something
    > similar in a non-Java program, and I want to avoid having to research the
    > percent formats for 23 different locales.
    >
    > I've done some searching, but haven't been able to find them. Can someone
    > point me in the right direction?


    Looking into the source "NumberFormat.java" I find
    ResourceBundle resource = LocaleData.getLocaleElements(desiredLocale);
    where class LocaleData is imported from package "sun.text.resources".
    I assume this call loads resources that same package.
    In file "<jre>/lib/rt.jar" there are many files
    sun/text/resources/LocaleElements_<locale>.class
    for european locales. And in file "<jre>/lib/ext/localedata.jar" there are
    some more for asian locales.

    --
    Thomas
    Thomas Fritsch, Feb 26, 2007
    #2
    1. Advertising

  3. Scott Smith

    Chris Uppal Guest

    Scott Smith wrote:

    > I need to format percentages for 23 different locales, and unfortunately
    > my client doesn't use Java. If I recall correctly, in Java I'd use
    > NumberFormat.getPercentInstance(locale) [or something like that], and the
    > JRE would get the appropriate percent formatting info from a
    > locale-specific resource bundle.
    >
    > OK, so... where are those resources? I basically need to do something
    > similar in a non-Java program, and I want to avoid having to research the
    > percent formats for 23 different locales.


    A) I should check the licensing position very carefully before using Sun's IP
    in a non-Java application.

    B) I think it depends on the Locale service provider.

    C) Why not just dump the data out of Java with a loop over
    NumberFormat.getAvailableLocales(), calling getPercentInstance() on each one ?

    D) The data included with the jre is in <jre>/lib/ext/localedata.jar. Inside
    the jar, the resource bundles are sun/text/resources/FormatData_*.class.

    E) The source for that isn't included in src.zip (further evidence that Sun
    regard this data as part of their private IP).

    F) The source /is/ included in the platform source download (hedged about by
    licencing restrictions).

    G) I would be willing to bet that the data for Java's number format stuff was
    supplied by IBM, and their code is available as the (impressive) ICU library
    for C, C++. and Java.
    http://icu.sourceforge.net/userguide/intro.html

    -- chris
    Chris Uppal, Feb 26, 2007
    #3
  4. Scott Smith

    Guest

    On Feb 26, 10:54 am, Thomas Fritsch <>
    wrote:
    > ScottSmithwrote:
    > > I need to format percentages for 23 different locales, and unfortunately
    > > my client doesn't use Java. If I recall correctly, in Java I'd use
    > > NumberFormat.getPercentInstance(locale) [or something like that], and the
    > > JRE would get the appropriate percent formatting info from a
    > > locale-specific resource bundle.

    >
    > > OK, so... where are those resources? I basically need to do something
    > > similar in a non-Java program, and I want to avoid having to research the
    > > percent formats for 23 different locales.

    >
    > > I've done some searching, but haven't been able to find them. Can someone
    > > point me in the right direction?

    >
    > Looking into the source "NumberFormat.java" I find
    > ResourceBundleresource = LocaleData.getLocaleElements(desiredLocale);
    > where class LocaleData is imported from package "sun.text.resources".
    > I assume this call loads resources that same package.
    > In file "<jre>/lib/rt.jar" there are many files
    > sun/text/resources/LocaleElements_<locale>.class
    > for european locales. And in file "<jre>/lib/ext/localedata.jar" there are
    > some more for asian locales.
    >
    > --
    > Thomas


    Thomas,

    Thanks very much. Found everything I needed!

    -Scott
    , Mar 1, 2007
    #4
  5. Scott Smith

    Guest

    On Feb 26, 10:57 am, "Chris Uppal" <-
    THIS.org> wrote:
    > ScottSmithwrote:
    > > I need to format percentages for 23 different locales, and unfortunately
    > > my client doesn't use Java. If I recall correctly, in Java I'd use
    > > NumberFormat.getPercentInstance(locale) [or something like that], and the
    > > JRE would get the appropriate percent formatting info from a
    > > locale-specific resource bundle.

    >
    > > OK, so... where are those resources? I basically need to do something
    > > similar in a non-Java program, and I want to avoid having to research the
    > > percent formats for 23 different locales.

    >
    > A) I should check the licensing position very carefully before using Sun's IP
    > in a non-Java application.
    >
    > B) I think it depends on the Locale service provider.
    >
    > C) Why not just dump the data out of Java with a loop over
    > NumberFormat.getAvailableLocales(), calling getPercentInstance() on each one ?
    >
    > D) The data included with the jre is in <jre>/lib/ext/localedata.jar. Inside
    > the jar, the resource bundles are sun/text/resources/FormatData_*.class.
    >
    > E) The source for that isn't included in src.zip (further evidence that Sun
    > regard this data as part of their private IP).
    >
    > F) The source /is/ included in the platform source download (hedged about by
    > licencing restrictions).
    >
    > G) I would be willing to bet that the data for Java's number format stuff was
    > supplied by IBM, and their code is available as the (impressive) ICU library
    > for C, C++. and Java.
    > http://icu.sourceforge.net/userguide/intro.html
    >
    > -- chris


    Chris,

    Thanks for the detailed reply. I was able to find the information that
    I needed with your help and the JAD decompiler. Someone could make a
    case about the IP issue, but I was looking at it more for reference
    than to lift code. Turns out that the percent formats are the same for
    all of the locales that I was interested in. Good to know.

    -Scott
    , Mar 1, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kiran
    Replies:
    2
    Views:
    5,141
    kiran
    Nov 2, 2005
  2. Joe Pribele

    rounding numberformat

    Joe Pribele, Aug 19, 2003, in forum: Java
    Replies:
    2
    Views:
    2,973
    Frank
    Aug 20, 2003
  3. HEP
    Replies:
    1
    Views:
    590
  4. mtp
    Replies:
    2
    Views:
    391
  5. StephaneLeFou

    NumberFormat vs double and long

    StephaneLeFou, Jun 11, 2008, in forum: Java
    Replies:
    4
    Views:
    405
    StephaneLeFou
    Jun 12, 2008
Loading...

Share This Page