JDK-4836629 : RFE: Add Currency Number to java.util.Currency
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.1
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-03-24
  • Updated: 2020-08-28
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 Other
7 b16Fixed OpenJDK6Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Name: rmT116609			Date: 03/24/2003


A DESCRIPTION OF THE REQUEST :
ISO 4217, the standard on which this class is based, defines two currency codes -- one alphabetic and one numeric.  The current version of the class implements only the alphabetic code and not the numeric.  For instance:

Currency curr = Currency.getInstance("USD");
System.out.println( "Currency Code = " + curr.getCurrencyCode() );

will print out:

Currency Code = USD

There is no method which will return the currency number.  I suggest a method such as

public int getCurrencyNumber(){}

In this way the currency number can be returned.


JUSTIFICATION :
1) The current class does not fully implement the ISO standard.

2) The numeric representation of the currency is used by banking facilities worldwide.

3) It is more efficient to use the numeric representation in comparisons.

4) The numeric representation of the currency may be used in "switch" constructs.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Currency curr = Currency.getInstance("USD");
System.out.println( "Currency Code = " + curr.getCurrencyCode() );
System.out.println( "Currency Number = " + String.valueOf(curr.getCurrencyNumber()) );

results in

Currency Code = USD
Currency Number = 840
Not implemented.

---------- BEGIN SOURCE ----------
public class TestCurrency
{

  public static void main( String args[] )
  {

    Currency curr = Currency.getInstance("USD");
    System.out.println( "Currency Code = " + curr.getCurrencyCode() );
    System.out.println( "Currency Number = " + String.valueOf(curr.getCurrencyNumber()) );

  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
package Test;

import java.util.Locale;

public class Currency
{
//Global constants
//Global variables
//Instance constants
//Instance variables
    java.util.Currency curr = null;
    
//Constructors
    public Currency( String currCode )
    {
        curr = java.util.Currency.getInstance(currCode);
    }
    
    public Currency( Locale currLocale )
    {
        curr = java.util.Currency.getInstance(currLocale);
    }

//Methods
    public String getCurrencyCode()
    {
        return( curr.getCurrencyCode() );
    }

    public int getCurrencyNumber()
    {
        String cCode = this.getCurrencyCode();
        
        if( cCode.equals("USD") ) return(840);
        return(0);
    }
    
    public static void main( String args[] )
    {
        try
        {
            Test.Currency curr = new Test.Currency("USD");
            int cCode = curr.getCurrencyNumber();
            
            System.out.println( String.valueOf(cCode) );
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

when runs, results in:

840

which is the numeric representation of the currency "USD".
(Review ID: 182955) 
======================================================================

Comments
SUGGESTED FIX http://javaweb.sfbay/jcg/7/i18n/6332666/
22-06-2007

EVALUATION Will be considered for the next major release. ###@###.### 2003-11-21
21-11-2003