Class Currency
This class should be used to denote any currency parameter. By default, the currency code is USD (US Dollars).
Following example shows how to use this class. ............. //inv is the Invoice object ............. *//Set the currency object. Currency mt = new Currency(new Double(25.12)); // A valid amount is a two decimal value. // For values which have more than two decimal places Currency amt = new Currency(new Double(25.1214)); amt.setNoOfDecimalDigits( 2); //If the NoOfDecimalDigits property is used then it is mandatory to set one of the following properties to true. amt.setRound (true); amt.setTruncate (true); *
//Set the amount in the invoice object inv.setAmt( Amt); .............
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected ContextGets the currency code.getError()Gets the error generated by the class.This should be used in case the toString() return blank.protected StringBufferGets the Requestbuffer used for creating the actual request string.protected StringroundCurrencyValue(String currStringValue, int noOfdecimalDigits) protected voidsetContext(Context context) voidsetNoOfDecimalDigits(int noOfDecimalDigits) Sets the number of decimal digits required after rounding or truncation.protected voidsetRequestBuffer(StringBuffer value) sets the StringBuffer to hold the request string.voidsetRound(boolean round) Sets Currency value rounding flag to true.voidsetTruncate(boolean truncate) Sets Currency value truncate flag to true.toString()Overrides ToStringprotected StringtruncateCurrencyValue(String currStringValue, int noOfdecimalDigits)
-
Constructor Details
-
Currency
Constructor- Parameters:
currValue- DoubleCurrency code is set as default USD.
............. //inv is the Invoice object ............. *//Set the invoice amount. inv.setAmt(new Currency(new Double(25.12))); *
.............
-
Currency
Constructor.- Parameters:
currencyValue- Double Currency valuecurrCode- String 3 letter Currency codeCurrency code if not given is set as default USD.
............. //inv is the Invoice object ............. *//Set the invoice amount. inv.setAmt(new Currency(new Double(25.12),"USD")); *
.............
-
-
Method Details
-
roundCurrencyValue
-
truncateCurrencyValue
-
toString
Overrides ToString -
getCurrencyCode
Gets the currency code.- Returns:
- currencyCode
-
setNoOfDecimalDigits
public void setNoOfDecimalDigits(int noOfDecimalDigits) Sets the number of decimal digits required after rounding or truncation.- Parameters:
noOfDecimalDigits- int
-
setRound
public void setRound(boolean round) Sets Currency value rounding flag to true.- Parameters:
round- boolean . Note that only one of round OR truncate can be set to true.
-
setTruncate
public void setTruncate(boolean truncate) Sets Currency value truncate flag to true.- Parameters:
truncate- boolean . Note that only one of round OR truncate can be set to true.
-
getError
Gets the error generated by the class.This should be used in case the toString() return blank.- Returns:
- error String
-
getContext
-
setContext
-
getRequestBuffer
Gets the Requestbuffer used for creating the actual request string.- Returns:
- mRequestBuffer StringBuffer
-
setRequestBuffer
sets the StringBuffer to hold the request string.- Parameters:
value- StringBuffer
-
generateRequest
protected void generateRequest()
-