DecimalFormat SetCurrency() Example
Sets the currency used by this number format
DecimalFormatclass SetCurrency() method example. This example shows you how to use SetCurrency() method.This method Sets the currency used by this number format when formatting currency values.
Here is the code:-
/**
* @Program that Sets the currency used by this number format when formatting
* currency values.
* SetCurrency.java
* Author:-RoseIndia Team
* Date:-13-Jun-2008
*/
import java.text.*;
import java.util.*;
public class SetCurrency {
public static void main(String[] args) {
// Creates a DecimalFormat object
DecimalFormat d = new DecimalFormat();
Currency c = Currency.getInstance("INR");
Currency c1 = Currency.getInstance("USD");
//Gets the currency used by this decimal format
System.out.println("Currency used by this decimal format before setting is : "
+d.getCurrency().getSymbol());
//Sets the currency used by this number format when formatting currency values.
d.setCurrency(c1);
System.out.println("Currency used by this decimal format after setting is : :"
+d.getCurrency().getSymbol());
}
} |
Output of the Program
Currency used by this decimal format before setting is : Rs.
Currency used by this decimal format after setting is : :USD |
|