NumberFormat SetCurrency() Example
Sets the currency used by this number format when formatting currency values.
NumberFormatclass 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:-17-Jun-2008
*/
import java.text.*;
import java.util.*;
public class SetCurrency {
public static void main(String[] args) {
//Creating Numberformat instance
NumberFormat nf = NumberFormat.getInstance();
System.out.println("Currency used by this number format is: "
+nf.getCurrency());
Currency c=Currency.getInstance("USD");
//Sets the currency used by this number format
nf.setCurrency(c);
System.out.println("Currency used by this number format is: "
+nf.getCurrency());
}
} |
Output of the program:-
Currency used by this number format is: INR
Currency used by this number format is: USD |
|