Java provides NumberFormat class to support currency formats based on local. All you need to do is get currency instance for NumberFormat class and calling format() method on top of the instance. An example is given below for your reference.
Sample Code:
import java.text.NumberFormat;
import java.util.Locale;
public class Currency {
public static void main(String a[]){
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
double currency = 52.12;
System.out.println("In Dollars: "+nf.format(currency));
nf = NumberFormat.getCurrencyInstance(Locale.UK);
System.out.println("In British Pound: "+nf.format(currency));
}
}
Output:
In Dollars: $52.12
In British Pound: £52.12
Search This Blog
Monday, April 5, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment