|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jec.functions.CurrencyFormat
This is a utility class for currency formatting and conversion. Use it to convert currency amounts between countries (example: EUR->ESP). You can just convert a 'double' amount, so it acts as a converter, or a 'double' to a formatted String.
To create a new CurrencyFormat object you need a factor map, which gives the relationship between amounts, and a format map, that specifies how a currency type must be transformed into a String.
factorMap is a Map with pairs String/Double with the relationships between currency types amounts. The default instance has 2 entries: "EUR"->"1.0d" and "ESP"->"166.386d". Notice that there's a reference currency with value "1.0d". Other currency values are relative to this reference currency type.
formatMap is a Map with pairs String/DecimalFormat with the relationships between currency types and their formatter (as they are 'doubles' their formatter are DecimalFormat objects).
The default CurrencyFormat has only 2 currency types: ESP and EUR.
Constructor Summary | |
CurrencyFormat(java.util.Map factorMap,
java.util.Map formatMap,
java.lang.String defaultCurrType)
Creates a new CurrencyFormat object given a factor map, which gives the relationship between amounts, and a format map, that specifies how a currency type must be transformed into a String. |
Method Summary | |
double |
convert(double amount,
java.lang.String idSource,
java.lang.String idTarget)
Converts an amount, given a source currency type, into a target currency amount. |
static CurrencyFormat |
getDefaultInstance()
Returns the default instance with ESP and EUR as the only currency types. |
double |
parseString(java.lang.String amount)
Parses an String expressed in a source currency type and converts it to a target currency type amount |
double |
parseString(java.lang.String amount,
java.lang.String idSource,
java.lang.String idTarget)
Parses an String expressed in a source currency type and converts it to a target currency type amount |
java.lang.String |
toString(double amount)
Formats an amount in the default currency type |
java.lang.String |
toString(double amount,
java.lang.String idSource,
java.lang.String idTarget)
Converts and formats an amount, given a source currency type, into a target currency format. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CurrencyFormat(java.util.Map factorMap, java.util.Map formatMap, java.lang.String defaultCurrType)
factorMap
- A Map with pairs String/Double with the relationships
between currency types amounts. The default instance has 2 entries:
"EUR"->"1.0d" and "ESP"->"166.386d". Notice that there's a reference
currency with value "1.0d". Other currency values are relative to this
reference currency type.formatMap
- A Map with pairs String/DecimalFormat with the relationships
between currency types and their formatter (as they are 'doubles' their
formatter are DecimalFormat objects).Method Detail |
public static CurrencyFormat getDefaultInstance()
public java.lang.String toString(double amount)
amount
- The amount to convert and formatpublic java.lang.String toString(double amount, java.lang.String idSource, java.lang.String idTarget)
amount
- The amount to convert and formatidSource
- The amount's currency typeidTarget
- The desired target currency typepublic double parseString(java.lang.String amount)
public double parseString(java.lang.String amount, java.lang.String idSource, java.lang.String idTarget)
public double convert(double amount, java.lang.String idSource, java.lang.String idTarget)
amount
- The amount to convertidSource
- The amount's currency typeidTarget
- The desired target currency type
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |